akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M, Q;
int a[200010];
int q[1010];

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

  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> q[i];
  }
  list<int> v(N);
  iota(v.begin(), v.end(), 0);
  auto curr = v.begin();
  for (int i = 0; i < M; i++) {
    if (a[i] & 1) {
      for (int j = 0; j < a[i]; j++) {
        if (curr == v.begin()) curr = --v.end();
        else curr--;
      }
    } else {
      for (int j = 0; j < a[i]; j++) {
        if (curr == --v.end()) curr = v.begin();
        else curr++;
      }
    }
    auto tmp = curr;
    if (curr == --v.end()) curr = v.begin();
    else ++curr;
    v.erase(tmp);
  }
  for (int i = 0; i < Q; i++) {
    cout << binary_search(v.begin(), v.end(), q[i]) << endl;
  }

  return 0;
}


Measured memory_bytes: 10136
package main

import (
        "bufio"
        "bytes"
        "fmt"
        "os"
)

func main() {
        var h, w int
        fmt.Scan(&h, &w)

        grid := make([]string, h+2)
        // 0.0 0.1 .. 0.w, 0.w+1
        // 1.0 1.1 .. 1.w, 1.w+1
        // h.0 h.1 .. h.w, h.w+1
        // h+1.0 h+1.1 .. h+1.w, h+1.w+1
        // make wall
        buf := bytes.NewBuffer([]byte{})
        for i := 0; i < w+2; i++ {
                buf.Write([]byte{'.'})
        }
        grid[0] = buf.String()
        grid[h+1] = buf.String()
        sc := bufio.NewScanner(os.Stdin)
        for i := 1; i <= h; i++ {
                sc.Scan()
                grid[i] = "." + sc.Text() + "."
        }
        // check paintable
        paintable := true
        for i := 1; i <= h; i++ {
                for j := 1; j <= w; j++ {
                        if grid[i][j] == '#' {
                                if grid[i-1][j] == '.' &&
                                        grid[i][j-1] == '.' &&
                                        grid[i+1][j] == '.' &&
                                        grid[i][j+1] == '.' {
                                        paintable = false
                                }
                        }
                }
        }
        if paintable {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

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


int main(){
  int N;
  cin>>N;
  int left=0,right=N-1;
  string L,R;
  
  cout<<left<<endl;
  cin>>L;
  if(L=="Vacant")return 0;
  
  cout<<right<<endl;
  cin>>R;
  if(R=="Vacant")return 0;
  
  while(1){
    int mid=(left+right)/2;
    cout<<mid<<endl;
    string M;
    cin>>M;
    if(M=="Vacant")break;

    int tmp=right-mid+1;
    if((tmp%2==1 && M!=R) || (tmp%2==0 && M==R)){
      left=mid;
      L=M;
    }else{
      right=mid;
      R=M;
    }
  }
  
  return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int A, B;
  cin >> A >> B;

  int Astart = (A-1)/4;
  Astart *= 4;
  int C = Astart;
  for( int i = Astart+1; i < A; i++ ){
    C ^= i;
  }
  int Bstart = B/4;
  Bstart *= 4;
  int D = Bstart;
  for( int i = Bstart+1; i <= B; i++ ){
    D ^= i;
  }
  int ans = C^D;
  cout << ans << endl;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

class UnionFind{
    public:
        vector<int> par;
        vector<int> rank;

        UnionFind(int n){
            for(int i = 0; i < n; i++){
                par.push_back(i);
                rank.push_back(0);
            }
        }

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

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

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

        bool same(int x, int y){
            return find(x) == find(y);
        }
};



int main(){
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    int inp0, inp1;

    REP(i,N){
        cin >> inp0;
        inp0--;
        p[i] = inp0;
    } 

    UnionFind uf(N);
    REP(i,M){
        cin >> inp0 >> inp1;
        inp0--;
        inp1--;
        uf.unite(inp0, inp1);
    }

    int num = 0;
    REP(i,N){
        if(uf.same(i, p[i]))
            num++;
    }
    cout << num << endl;
    return 0;
}


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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int a, b; cin >> a >> b;
        cout << max({a+ b, a-b,a*b})
;}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>

#define sqr(x) ((x) * (x))

double distance(double x1, double y1, double x2, double y2) {
	return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

int main() {
	double xa, ya, ra, xb, yb, rb;
	int n;
	double dis;

	int i;

	scanf("%d", &n);

	for(i = 0; i < n; i++) {
		scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);

		dis = distance(xa, ya, xb, yb);

		if(ra + rb < dis)
			printf("0\n");

		else if(ra > rb && ra - rb > dis)
			printf("2\n");

		else if(rb > ra && rb - ra > dis)
			printf("-2\n");

		else
			printf("1\n");
	}

	return 0;
}

Measured memory_bytes: 620
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  char c; cin >>c;
  printf("%c",c+1);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  vector<vector<int>> a(25, vector<int>(25));
  rep(i,n){ rep(j,n){ cin>>a[i][j]; }}
  vector<vector<ll>> dp(22, vector<ll>((1LL<<22),0)); //faster global ll dp[22][(1LL<<22)];
  
  dp[0][0]=1;					//dp[i][bit]:otoko i made,zyosei pair bit: x toori 
  rep(i,n)rep(j,1LL<<n)if(dp[i][j]){  
    rep(k,n)if(bit(j,k)==0&&a[i][k]==1){
      dp[i+1][j|1LL<<k] = (dp[i+1][j|1LL<<k]+dp[i][j])%mod;
    }
  } //kubaru DP nara if de edagiri dekiru
  
  ll ans = dp[n][(1LL<<n)-1];
  cout << ans << endl;
  return 0;
}

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

int main(){
    int H,W;
    while(1){
        scanf("%d %d",&W,&H);
        if(W==0&&H==0) break;
        for (int i=0;i<W;i++){
            for (int j=0;j<H;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 3128
import sys
sys.setrecursionlimit(1000000)
import itertools


def calc(abcd, As, N):
    score = 0
    for a, b, c, d in abcd:
        if As[b-1] - As[a-1] == c:
            score += d
    return score

def solve(N, M, Q, abcd):

    score = 0
    for a1 in range(1, M+1):
        for a2 in range(a1, M+1):
            for a3 in range(a2, M+1):
                for a4 in range(a3, M+1):
                    for a5 in range(a4, M+1):
                        for a6 in range(a5, M+1):
                            for a7 in range(a6, M+1):
                                for a8 in range(a7, M+1):
                                    for a9 in range(a8, M+1):
                                        for a10 in range(a9, M + 1):
                                            score = max(score, calc(abcd, [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10], N))

    return score

if __name__ == "__main__":
    N, M, Q = tuple(map(int, input().split(" ")))
    abcd = []
    for _ in range(Q):
        abcd.append(tuple(map(int, input().split(" "))))
    print(solve(N, M, Q, abcd))


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

int main()
{
	int n, d, x, k, sum=0;
	cin>>n;
	cin>>d>>x;
	while(n--)
	{
		cin>>k;
		sum+=(d-1)/k+1;
	}
	sum+=x;
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int x,y,temp,gcd;

	scanf("%d %d",&x,&y);

	if(x>=y){
		while(x%y!=0){
			x=x%y;
			temp=x;
			x=y;
			y=temp;
		}
		gcd=y;
	}else if(y>x){
		while(y%x!=0){
			y=y%x;
			temp=x;
			x=y;
			y=temp;
		}
		gcd=x;
	}
	printf("%d\n",gcd);

	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n,m,p;cin >> n >> m >>p;
		m--;
		if( n == 0)break;
		vector<int> x(n);
		for(int i = 0; i < n; i++){
			int t; cin >> t;
			x[i] = t;
		}
		int sum = accumulate(x.begin(), x.end(), 0);
		int ans = x[m] == 0 ? 0 : sum * (100 - p) / x[m];
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n;
    cin>>n;
    vi a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans=0;
    vi pos(n);
    vc<ll> suf(n);
    for(int i=0;i<n;i++)
        pos[i]=n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
    for(int i=n-1;i>=0;i--)
    {
        suf[i]=pos[i];
        if(i<n-1) suf[i]+=suf[i+1];
    }
    for(int i=0;i<n;i++)
    {
        int p=upper_bound(b.begin(),b.end(),a[i])-b.begin();
        if(p!=n) ans+=suf[p];
    }
    print(ans);
    
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int n,one=0;
   string xx;
   cin>>n>>xx;
   for(int i=0;i<xx.size();i++){
   	if(xx[i]=='1') one++;
   }
 
   int p=0,q=0,r=1,s=1;
   for(int i=n-1;i>=0;i--){
     if(xx[i]=='1'){
    	p=(p+r)%(one+1);
        if(one!=1) q=(q+s)%(one-1);
    }
     r=(r*2)%(one+1);
    if(one!=1) s=(s*2)%(one-1);
   }
   vector<int> ans(n,0),now(n);
   int x=1,y=1;
   for(int i=n-1;i>=0;i--){
   	 if(xx[i]=='1'){
     	if(one!=1) now[i]=(q+(one-1-x))%(one-1);
        else{
        	now[i]=0;
            ans[i]=-1;
        }
     }else{
     	now[i]=(p+y)%(one+1);
     }
     if(one!=1)x=(x*2)%(one-1);
     y=(y*2)%(one+1);
     if(now[i]!=0) ans[i]++;
   }
   for(int i=0;i<n;i++){
   	if(ans[i]==1){
        one=0;
    	for(int j=0;j<22;j++){
        	if(now[i]&(1<<j)) one++;
        }
        now[i]=now[i]%one;
        if(now[i]!=0) ans[i]++;
    }
   }
    for(int i=0;i<n;i++){
      if(ans[i]==2){
          one=0;
          for(int j=0;j<8;j++){
              if(now[i]&(1<<j)) one++;
          }
          now[i]=now[i]%one;
          if(now[i]!=0) ans[i]++;
      }
     }
    for(int i=0;i<n;i++){
        if(ans[i]==3){
            one=0;
            for(int j=0;j<5;j++){
                if(now[i]&(1<<j)) one++;
            }
            now[i]=now[i]%one;
            if(now[i]!=0) ans[i]++;
        }
       }
   for(int i=0;i<n;i++){
        if(ans[i]==4){
            one=0;
            for(int j=0;j<4;j++){
                if(now[i]&(1<<j)) one++;
            }
            now[i]=now[i]%one;
            if(now[i]!=0) ans[i]++;
        }
       }
  for(int i=0;i<n;i++){
        if(ans[i]==5){
            one=0;
            for(int j=0;j<3;j++){
                if(now[i]&(1<<j)) one++;
            }
            now[i]=now[i]%one;
            if(now[i]!=0) ans[i]++;
        }
       }
  for(int i=0;i<n;i++){
        if(ans[i]==6){
            one=0;
            for(int j=0;j<2;j++){
                if(now[i]&(1<<j)) one++;
            }
            now[i]=now[i]%one;
            if(now[i]!=0) ans[i]++;
        }
       }
  for(int i=0;i<n;i++){
        if(ans[i]==7){
            one=0;
            for(int j=0;j<1;j++){
                if(now[i]&(1<<j)) one++;
            }
            now[i]=now[i]%one;
            if(now[i]!=0) ans[i]++;
        }
       }

  for(int i=0;i<n;i++){
  	cout<<ans[i]+1<<endl;
  }
}

Measured memory_bytes: 5228
/* JOI7.c */
#include <stdio.h>
int main(void)
{
 int hA[3],hB[3]; //h,s,mAが入社時刻 h,s,m,Bが退社時刻
 int mA[3],mB[3];
 int sA[3],sB[3];
 int i;
 int time[3];

 for(i=0; i<3; i++){
 scanf("%d %d %d %d %d %d",&hA[i],&mA[i],&sA[i], &hB[i],&mB[i],&sB[i]);
 time[i] =( (3600*hB[i]+60*mB[i]+sB[i])-(3600*hA[i]+60*mA[i]+sA[i]) ); 
 }

 //time[i]には、在宅時間を秒に直したものが入っている。

 for(i=0; i<3; i++)
 printf("%d %d %d\n",time[i]/3600,(time[i]/60)%60,time[i]%60);
 
 return 0;
 }

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n;

    cin >> n;
    vector<int> a(n);

    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[n - 1] - a[0] << endl;

    return 0;
}


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

using namespace std;

long long ans,a,b,n,i;

int main()
{
    cin >> n;
    for(i = 0; i < n; i ++)
    {
        cin >> a;
        ans += (a + b) / 2;
        if((a + b) % 2 == 1 && a != 0) b = 1;
        else b = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize ("O2")
typedef long long LL;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
void OUT(LL x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main(void)
{
  static int K=1;const int N=IN();static LL a=0;
  while(K<=N){const int div=N/(N/K)+1;a+=1ll*(div-K)*(K+div-1)*(N/K)*(N/K+1)/4;K=div;}
  return OUT(a),0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
	int a, b, c, d;
	while(~scanf("%d %d %d %d", &a, &b, &c, &d)) {
		if( abs(c - a) <= d || (abs(b-a) <= d && abs(c-b) <= d) ) {
			printf("Yes\n");
		} else printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
#define int long long


signed main(){
    int n; cin >> n;
    string ans = "";
    while(n > 0){
        n--;//10進数における0がないことに対応
        char c = 'a' + n % 26;
        n /= 26;
        ans = c + ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
n = int(input())
a = list(map(int,input().split()))
ans = 'APPROVED'
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            ans = 'DENIED'
print(ans)

Measured memory_bytes: 38716
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


int n;
vector<int> x(0);
queue<int> q;

int gcd(int p, int q){
    if(p < q) swap(p, q); // always p >= q
    if(p%q == 0) return q;
    else return gcd(q, p%q);
}

int main(){
    int a;
    int s, t;
	cin >> n;
    for(int i=0;i<=n;i++){
        cin >> a;
        x.push_back(a);
    }
    sort(x.begin(), x.end());
    for(int i=0;i<n;i++){
        q.push(x[i+1] - x[i]);
    }

    s = q.front();
    q.pop();
    while(q.size()){
        t = q.front();
        q.pop();
        s = gcd(s, t);
    }
    cout << s << endl;

	return 0;
}


Measured memory_bytes: 1016
def partition(A, p, r):
    x, i = A[r], p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

n = int(input())
A = list(map(int,input().split()))
s = partition(A,0,n-1)
print(*A[:s],end = ' ')
print([A[s]],end = ' ')
print(*A[s+1:])

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

int main(){
    int n, k;
    while(cin >> n >> k){
        if(!n&&!k) break;
        int A[n]={0}, S[n+1]={0};
        for(int i=0;i<n;i++) {
            cin >> A[i];
            S[i+1] = S[i]+A[i];
        }
        int maxValue = -600000000;
        for(int i=0;i+k<=n;i++){
            maxValue = max(maxValue, S[k+i]-S[i]);
        }
        cout << maxValue << endl;
    }
    //cout << "finished" << endl;
    return 0;
}


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

bool f(const long kind, const size_t n, const vector<long>& a){
    map<long,long> c;
    long len = a[0];
    for(size_t i=1; i<n; i++){
        const long n_len = a[i];
        if(len>=n_len){
            c.erase(c.lower_bound(n_len), c.end());
            long j=n_len-1;
            for(;;){
                c[j]++;
                if(c[j]<kind){
                    c.erase(c.upper_bound(j), c.end());
                    break;
                }else if(j<=0){
                    return false;
                }else{
                    //c[j]=0;
                    j--;
                }
            }
        }
        len = n_len;
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


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

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

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

int N;
int L[102];
int mask[102];
ll dp[102][1<<16];

ll dfs(int a,int b) {
    if(a==N) return 0;
    if(dp[a][b]!=-1) return dp[a][b];

    ll res=0;
    res=max(res,dfs(a+1,b));
    if((b&mask[a])==0)
        res=max(res,dfs(a+1,b|mask[a])+L[a]);

    return dp[a][b]=res;
}

void solve() {
    rep(i,102) mask[i]=0;
    memset(dp,-1,sizeof(dp));
    rep(i,N) {
        int m;
        cin>>m>>L[i];
        rep(j,m) {
            int s,e;
            cin>>s>>e;
            s-=6;
            e-=6;
            for(int k=s;k<e;k++) mask[i] |= 1<<k;
        }
    }
    cout<<dfs(0,0)<<endl;


}

int main() {
    ios::sync_with_stdio(false);
    while(cin>>N) {
        if(!N) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 53424
from itertools import permutations as perm

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = list(range(1, n + 1))

def f(p, q):
    for i, j in zip(p, q):
        if i != j:
            return False
    return True

aa,bb = -1,-1
for i, p in enumerate(perm(l)):
    if f(p, a):
        aa = i
    if f(p, b):
        bb = i
print(abs(aa - bb))
# print(aa,bb)

Measured memory_bytes: 45788
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN = 2 * 1e5 + 10;
int a[MAXN];
int n;

int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	if(n % 2 == 0){
		for(int i = n ; i >= 2 ; i -= 2)
			cout << a[i] << " ";
		for(int i = 1 ; i <= n ; i += 2)
			cout << a[i] << " ";
		cout << endl;
	}
	else{
		for(int i = n ; i >= 1 ; i -= 2)
			cout << a[i] << " ";
		for(int i = 2 ; i <= n ; i += 2)
			cout << a[i] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner

fun main(args: Array<String>){
  val cin = Scanner(System.`in`)
  val a = cin.next()
  val b = cin.next()
  val c = cin.next()

  if (a[a.length - 1] == b[0] && b[b.length - 1] == c[0]){
    println("YES")
  }
  else {
    println("NO")
  }
  cin.close()
}

Measured memory_bytes: 31264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String inputLine = sc.nextLine();
		int insideHead = 0;
		for(int i = 0;i < inputLine.length();++i)
			if(inputLine.charAt(i) == '+')
				++insideHead;
			else if(inputLine.charAt(i) == '-')
				--insideHead;
		System.out.println(insideHead);
      sc.close();
	}
}


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

int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }
    int count = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            for (int k = j+1; k < n; k++){
                if(data.at(i) == data.at(j) || data.at(j) == data.at(k) || data.at(k) == data.at(i))
                continue;
                if(abs(data.at(i) - data.at(j)) < data.at(k) && data.at(k) < data.at(i) + data.at(j))
                count ++;
            }
        }
    }
    cout << count << endl;
}

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

bool test(const int &a, const int &b){
    return a < b;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int,int,int>> yp(m);
    for(int i = 0;i < m;i++){
        cin >> get<0>(yp[i]) >> get<1>(yp[i]);
        get<2>(yp[i]) = i;
    }

    sort(yp.begin(),yp.end());

    int ans = 1;
    for(int i = 0;i < m;i++){
        get<1>(yp[i]) = ans;
        if(i == m - 1) break;
        if(get<0>(yp[i]) == get<0>(yp[i + 1]))
        {
            ans++;
        }
        else{
            ans = 1;
        }
    }

    sort(yp.begin(),yp.end(),
        [](tuple<int,int,int> const& L, tuple<int,int,int> const& R)
        {
            return get<2>(L) < get<2>(R);
        }
    );

    for(int i = 0;i < m;i++){
        cout << setfill('0') << right << setw(6) << get<0>(yp[i]) << setfill('0') << right << setw(6) << get<1>(yp[i]) << endl;
    }
    


    return 0;
}

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

const int maxn = 500010;
int n, a[maxn];
char s[maxn];

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = s[n - i + 1] - '0';
    }
    int sum = 0;
    auto mul = [&]() {
        int t = 0;
        for (int i = 1; i <= n; i++) {
            t += a[i] * 9;
            a[i] = t % 10, sum += a[i], t /= 10;
        }
        if (t) a[++n] = t, sum += t;
    };
    mul();
    auto inc = [&]() {
        int t = 9;
        for (int i = 1; i <= n; i++) {
            t += a[i], sum -= a[i];
            a[i] = t % 10, sum += a[i], t /= 10;
            if (!t) break;
        }
        if (t) a[++n] = t, sum += t;
    };
    for (int i = 1; ; i++) {
        inc();
        if (i * 9 >= sum) printf("%d\n", i), exit(0);
    }
    return 0;
}

Measured memory_bytes: 6252
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<int> to[100005];
vector<int> dist;

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : to[v]) {
        if (u == p) continue;
        dfs(u, d+1, v);
    }
}

int main()
{
    int n,u,v;
    cin >> n >> u >> v;
    u--;
    v--;
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dist = vector<int>(n);
    dfs(u);
    vector<int> du = dist;
    dist = vector<int>(n);
    dfs(v);
    vector<int> dv = dist;

    int ans = 0;
    for(int i=0; i<n;i++){
        if(dv[i] <= du[i] ) continue;
        ans = max(ans, dv[i] -1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10744
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
   int D;
   cin>>D;

   if(D==25){
       cout<<"Christmas"<<endl;
       return 0;
   }
   else if(D==24){
       cout<<"Christmas Eve"<<endl;
       return 0;
   }
   else if(D==23){
       cout<<"Christmas Eve Eve"<<endl;
       return 0;
   }
   else if(D==22){
       cout<<"Christmas Eve Eve Eve"<<endl;
       return 0;
   }

}


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

const int MOD = 1e9 + 7;

int h, w, d[3] = {0, 1, 0};
int dp[1010][1010], grid[1010][1010];

int solve(int i, int j) {
	if (i == h && j == w) return 1;
	if (dp[i][j] != -1) return dp[i][j];
	
	int ans = 0;
	
	for (int k = 0; k < 2; ++k) {
		int ni = i + d[k], nj = j + d[k+1];
		if (ni <= h && nj <= w && grid[ni][nj]) {
			ans = (ans + solve(ni, nj)) % MOD;
		}
	}
	
	return dp[i][j] = ans%MOD;
}

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

	cin >> h >> w;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			char c; cin >> c;
			grid[i][j] = (c=='.');
			dp[i][j] = -1;
		}
	}

	cout << solve(1, 1) << "\n";
	
	return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define re register
using namespace std;
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
const int maxn=100010,maxm=500010;
int n,m,val[maxn],front[maxn],cnt,uu[maxn],vv[maxn],color[maxn];
int dfn[maxn],low[maxn],TIME,vis[maxn],sta[maxn],sss,all;
int sum[maxn],dp[maxn];
struct node{
    int to,nxt;
}e[maxm];
void Add(int u,int v){
    e[++cnt]=(node){v,front[u]};front[u]=cnt;
}
void Tarjan(int u){
    dfn[u]=low[u]=++TIME;vis[u]=1;sta[++sss]=u;
    for(re int i=front[u];i;i=e[i].nxt){
        int v=e[i].to;
        if(!dfn[v]){
            Tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(vis[v])low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        color[u]=++all;vis[u]=0;
        while(sta[sss]!=u){
            int v=sta[sss--];
            color[v]=all;vis[v]=0;
            sum[all]++;
        }
        sum[all]++;sss--;
    }
}
void DP(int u){
    if(dp[u])return;dp[u]=sum[u];
    int bigger=0;
    for(re int i=front[u];i;i=e[i].nxt){
        int v=e[i].to;
        if(!dp[v])DP(v);
        bigger=max(bigger,dp[v]);
    }
    dp[u]+=bigger;
}
int main(){
    n=gi();m=gi();
    for(re int i=1;i<=m;i++){
        int a=gi(),b=gi();Add(a,b);
        uu[i]=a;vv[i]=b;
    }
    for(re int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
    memset(front,0,sizeof(front));cnt=0;
    for(re int i=1;i<=m;i++){
        int u=uu[i],v=vv[i];
        if(color[u]!=color[v]){
            Add(color[u],color[v]);
        }
    }
    int ans=0;
    for(re int i=1;i<=all;i++)
        if(!dp[i]){
            DP(i);
            ans=max(ans,dp[i]);
        }
    printf("%d\n",ans-1);
    return 0;
}


Measured memory_bytes: 9216
#!/usr/bin/python3

import sys

def input():
    return sys.stdin.readline().rstrip('\n')

#N = int(input())
S = input()
#D = list(map(int, input().split()))

length = len(S)
counter = 0

for i in range(length // 2):
    left = S[i]
    right = S[-(i+1)]
    #print(left,right)
    if left == right:
        continue
    else:
        counter +=1

print(counter)


Measured memory_bytes: 2940
class Dice:
    """????????????????????????"""
    def __init__(self, s):
        self.s1 = s[0]
        self.s2 = s[1]
        self.s3 = s[2]
        self.s4 = s[3]
        self.s5 = s[4]
        self.s6 = s[5]

    def roll(self, direction):          # ???????????????????§??????¢????????¢
        temp = self.s1
        if direction == "E":
            self.s1 = self.s4
            self.s4 = self.s6
            self.s6 = self.s3
            self.s3 = temp
        elif direction == "N":
            self.s1 = self.s2
            self.s2 = self.s6
            self.s6 = self.s5
            self.s5 = temp
        elif direction == "S":
            self.s1 = self.s5
            self.s5 = self.s6
            self.s6 = self.s2
            self.s2 = temp
        elif direction == "W":
            self.s1 = self.s3
            self.s3 = self.s6
            self.s6 = self.s4
            self.s4 = temp

    def setposition(self, a, b):
        while 1:
            if self.s1 == a:
                break
            self.roll("N")
            if self.s1 == a:
                break
            self.roll("E")
        while 1:
            if self.s2 == b:
                break
            self.roll("N")
            self.roll("E")
            self.roll("S")


s = list(map(int, input().split()))
dice1 = Dice(s)
q = int(input())

for _ in range(q):
    a, b = map(int, input().split())
    dice1.setposition(a, b)
    print(dice1.s3)

Measured memory_bytes: 7820
#include <bits/stdc++.h>
using namespace std;
typedef long long 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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/


ll black, white;
int d1[4] = {1,0,-1,0};
int d2[4] = {0,1,0,-1};
vector<vector<bool>> seen(450, vector<bool>(450, false));
vector<vector<char>> fi(450, vector<char>(450, '0'));

void dfs(int i, int j, char c){
    if(c == '.') white++;
    else black++;

    for(int k=0; k<4; k++){
        int nx = i+d1[k];
        int ny = j+d2[k];
        if(seen[nx][ny] == false && fi[nx][ny] != '0' && fi[nx][ny] != c){
            seen[nx][ny] = true;
            dfs(nx, ny, fi[nx][ny]);
        }
    }
    
}


int main(){
    int H, W; cin >> H >> W;
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) cin >> fi[i][j];

    ll ans = 0;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(!seen[i][j]){
                black = 0, white = 0;
                seen[i][j] = true;
                dfs(i, j, fi[i][j]);
                ans += black*white;
            }
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 8064
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _s(): return sys.stdin.readline().strip()


def main():
    s = _s()
    hi = ["hi"*i for i in range(1, 6)]
    if s in hi:
        return "Yes"
    else:
        return "No"


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


Measured memory_bytes: 38256
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day6.cpp -o day6 -std=c++11 -O2  | to run: ./(name of file)  //

string S;

int main() {
    cin >> S;
    int N = S.length();
    for ( int i = 0; i < N; i+=2 ) {
        if ( S[i] == 'L' ) {
            cout << "No";
            return 0;
        }
    }
    for ( int i = 1; i < N; i+=2 ) {
        if ( S[i] == 'R' ) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

string S;
int cou=0;

int main(){
    cin>>S;
    rep(i,3){
        if(S[i]=='1')cou++;
    }
    out(cou);
}


Measured memory_bytes: 256
#python3
import numpy as np
n,d=map(int, input().split())
pos=[[int(i) for i in input().split()] for _ in range(n)]

def isInt(a, b):
  sum=0;
  for i in range(d):
    sum+=(a[i]-b[i])**2

  tmp=sum**(0.5) 
  if tmp==np.floor(tmp):
    return True
  else: False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    if isInt(pos[i],pos[j]):
      cnt+=1
print(cnt)

    

Measured memory_bytes: 18404
import sys
import numpy as np


def input():
    return sys.stdin.readline().strip()


def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    A.append(K + A[0])
    B = np.array(A[1:])
    A = np.array(A[:-1])
    Diff = B - A
    max_diff = max(Diff)
    answer = K - max_diff
    return answer


if __name__ == "__main__":
    answer = main()
    print(answer)


Measured memory_bytes: 34168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    int pre = 0;
    for(int i = 0; i < S.size() - 1; i++) {
        if(S[i] == S[i + 1]) {
            N--;
        }
    }

    cout << N << endl;
}


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

int main() {
  int N;
  cin >> N;
   
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
   cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
    
   int sumA =0;
  for(int i = 0; i < N; i+=2){
   sumA += vec.at(i);
  }
  
    int sumB =0;
  for(int i = 1; i < N; i+=2){
   sumB += vec.at(i);
  }

  cout << sumA-sumB << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}
	for (int i = 0; i < 3; ++i)
	{
		for (int j = i + 1; j < 3; ++j)
		{
			if (a[j] < a[i])
			{
				int temp = a[j];
				a[j] = a[i];
				a[i] = temp;
			}
		}
	}
	for (int i = 0; i < 2; ++i)
	{
		cout << a[i] << " ";
	}
	cout << a[2] << endl;
}

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

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

	using namespace std;

	int main() {
		int n; cin >> n;
		int a[n];
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0;
		for(int i : a) {
			while(i % 2 == 0) {
				sum++;
				i /= 2;
			}
		}
		cout << sum;
	}


Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string N = Console.ReadLine();
        string n = new string(N.Reverse().ToArray());
        if(N == n)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    REP(i, N) cin >> l[i];

    int ans = INF;
    REP(i, 1 << (2 * N)) {
        int mp = 0;
        int a = 0;
        int b = 0;
        int c = 0;
        REP(j, N) {
            int kind = (i >> (j * 2)) & 3;
            if (kind == 0) continue;
            if (kind == 1) {
                if (a > 0) mp += 10;
                a += l[j];
            }
            if (kind == 2) {
                if (b > 0) mp += 10;
                b += l[j];
            }
            if (kind == 3) {
                if (c > 0) mp += 10;
                c += l[j];
            }
        }
        if (a == 0 || b == 0 || c == 0) continue;
        mp += abs(A - a) + abs(B - b) + abs(C - c);
        ans = min(mp, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

const int N=100005;
vector<vi> dp;
vi a;
int n;

int cal(int k,int turn)
{		
	if(dp[k][turn]!=-1)
		return dp[k][turn];


	int ans=!turn;

	for(int i=0;i<n;++i)
		if(k>=a[i])
		{	
			if(turn==0)
				ans&=cal(k-a[i],!turn);
			else ans|=cal(k-a[i],!turn);
		}
	return dp[k][turn]=ans;
}

int32_t main()
{
	fastIO
//	inp_out();
	int k;
	cin>>n>>k;
	dp=vector<vi>(N,vi(2,-1));
	a=vi(n);
	for(int i=0;i<n;++i)
		cin>>a[i];
	cout<<(cal(k,0)==0?"First":"Second");
	return 0;
}


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

// DPテーブル
const int MAX_N = 1001;
const int MAX_W = 11000;
long long dp[MAX_N][MAX_W]; // 12 種類だが余裕をもつ

int main() {
    long long W,N;
    cin >> W>>N;

    // 品物を列挙 (価値はすべて 1)
    vector<long long> weight;
    vector<long  long> value;
    for (int i = 0; i < N; i++)
    {
        long long a, b;
        cin >> a >> b;
        weight.push_back(a);
        value.push_back(b);
    }
    long long n = (long long)weight.size();

    // DP初期条件: dp[i][0] = 0
    for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = 1 << 29; // INF
    for (int i = 0; i <= n; ++i) dp[i][0] = 0;
    dp[0][0] = 0;
    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= MAX_W; ++w) {
            dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
            if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - weight[i]] + value[i]);
        }
    }
    long long minn = 1 << 29;
    for (int i = W; i < MAX_W;i++){
        if(minn>dp[N][i]){
            minn = dp[N][i];
        }
    }
    

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


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << abs(c+(b-min(a,b+c))) << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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

def solve():
  n = int(input())
  query = []
  xquery = []
  yquery = []
  for i in range(n):
    x,y = (int(i) for i in input().split())
    xquery.append((x,y,i))
    yquery.append((y,x,i))
  xquery.sort()
  yquery.sort()
  for i in range(n-1):
    tx,ty,place = xquery[i]
    tx2,ty2,place2 = xquery[i+1]
    cost = min(abs(tx2-tx),abs(ty2-ty))
    if place > place2:
      place,place2 = place2,place
    heapq.heappush(query,(cost,place,place2))
    
    ty,tx,place = yquery[i]
    ty2,tx2,place2 = yquery[i+1]
    cost = min(abs(tx2-tx),abs(ty2-ty))
    if place > place2:
      place,place2 = place2,place
    heapq.heappush(query,(cost,place,place2))
  ct = 0
  uf = UnionFind(n)

  while len(query) > 0:
    cost,place1,place2 = heapq.heappop(query)
    if uf.same_check(place1,place2):
      continue
    else:
      uf.union(int(place1),int(place2))
      ct += cost
  print(ct)
      

solve()

Measured memory_bytes: 57180
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<=n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}


int n;
void dfs(string s,char x){
    if(s.size()==n){
        cout << s << endl;
    }
    else{
        for(char a='a';a<=x;a++){
            dfs(s+a,a==x ? (char) x+1 : x);
        }
    }
}

int main(){
    cin >> n;
    dfs("",'a');
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	int add = min(a - b, c);
	c -= add;
	cout << c;
}	


Measured memory_bytes: 256
//B - Break Number: 
//Assunto: Math;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int solve(int x) {
    //cout << x << "\n";
    int a = 0;
    while(x % 2 == 0) {
        a++;
        x /= 2;
    }
    //cout << a << "\n";
    return a;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, maxi = 0, aux, ans = 1;
    cin >> n;
    for(int i = 2; i <= n; i += 2) {
        aux = solve(i);
        if(aux > maxi) {
            maxi = aux;
            ans = i; 
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256