akhauriyash/Code-Regression huggingface dataset:
from collections import namedtuple

Card = namedtuple('Card', ['suit', 'value', 'init'])

def QuickSort(A, begin, end):
    if end - begin <= 1:
        return

    piv = A[end - 1].value
    left, right = begin, begin

    for i in range(begin, end - 1):
        if A[i].value <= piv:
            if i - left > 0:
                A[left], A[i] = A[i], A[left]
            left += 1

    A[left], A[end - 1] = A[end - 1], A[left]

    QuickSort(A, begin, left)
    QuickSort(A, left + 1, end)

n = int(input())

A = []

for i in range(n):
    suit, value = input().split()
    value = int(value)
    A.append(Card(suit, value, i))

QuickSort(A, 0, n)

for i in range(n - 1):
    if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:
        print('Not stable')
        break
else:
    print('Stable')

for a in A:
    print(a.suit, a.value)

Measured memory_bytes: 23628
#include <stdio.h>
#include <string.h>
int main(){
  int culc=0;
  int stack[200];
  char line[10];
  int index=0;					/* スタックのトップの添字 */
  int tmp_num1;
  int tmp_num2;
  int i;
  //初期化
  for(index=0; index<200; ++index){
	stack[index]=0;
  }
  index=-1;
  //
  while(scanf("%s", line)!=EOF){
	if(strcmp(line,"end")==0)
	  break;
	if(strcmp(line, "+")==0){
	  tmp_num2=stack[index];
	  --index;
	  tmp_num1=stack[index];
	  culc=tmp_num1+tmp_num2;
	  stack[index]=culc;
	}else if(strcmp(line, "-")==0){
	  tmp_num2=stack[index];
	  --index;
	  tmp_num1=stack[index];
	  culc=tmp_num1-tmp_num2;
	  stack[index]=culc;
	}
	else if(strcmp(line, "*")==0){
	  tmp_num2=stack[index];
	  --index;
	  tmp_num1=stack[index];
	  culc=tmp_num1*tmp_num2;
	  stack[index]=culc;
	}
	else{
	  ++index;
	  sscanf(line, "%d", &stack[index]);
	}
	/* for(i=0; i<=index; ++i){ */
	/*   printf("stack: %d ", stack[i]); */
	/*   if(i<index) */
	/* 	printf(" "); */
	/*   else */
	/* 	printf("\n"); */
	/* } */
  }
  printf("%d\n", stack[index]);
  return 0;
}



Measured memory_bytes: 2100
test_mode = False #True
if test_mode:
    import random
    N = random.randint(1,10**9)
    print(N)

def ask(n):
    print('?', n)
    if not test_mode:
        ans = input().rstrip()
    else:
        ans = 'Y' if (n <= N and str(n) <= str(N)) or (n > N and str(n) > str(N)) else 'N'
    return ans == 'Y'

def solve():
    if ask(10**10):
        # power of 10
        for n in range(10,0,-1):
            if not ask(10 ** n - 1):
                return 10 ** n
        return 1
    # 以下10のべき乗以外
    d = 10
    while not ask(10 ** d):
        # 10 のべきを投げると、辞書順では自動で勝つ
        # よって、NO = n\leq 10^d
        d -= 1
    d += 1
    # Nはd桁
    left = 10 ** (d-1) # Nより小さい
    right = 10 ** d - 1 # N以上
    while right > left + 1:
        mid = (left + right) // 2
        if ask(mid * 10 ** 9):
            # 数字順では勝つ
            # 辞書順でmid >= NのときにTrue
            right = mid
        else:
            left = mid
    return right

answer = solve()
print('!', answer)

Measured memory_bytes: 3404
#include<string.h>
#include<iostream>
using namespace std;
int main(){
  int found=0;
  string S;
  cin>>S;
  long long L=S.size();
  for(int i=0;i<L-1;i++){
    if(S[i]==S[i+1]){
      found=1;
      break;
    }
  }
  if(found==1)
    cout<<"Bad";
    else
      cout<<"Good";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, mp[25][25], ac[25][25], f, tw, fv;
char c;
long long a, ans;
int main(){
	while(getchar() != '\n');
	while((c = getchar()) != EOF){
		if(c == '\n'){
			for(; a%2==0; a/=2, tw++); if(tw>10)tw=10;
			for(; a%5==0; a/=5, fv++); if(fv>10)fv=10;
			mp[tw+10][fv+10]++;
			a = tw = fv = f = 0;
		}else if(c == '.') f=1;
		else{
			tw -= f; fv -= f;
			a = a*10 + c-'0';
		}
	}
	if(a){
		for(; a%2==0; a/=2, tw++); if(tw>10)tw=10;
		for(; a%5==0; a/=5, fv++); if(fv>10)fv=10;
		mp[tw+10][fv+10]++;
	}
	for(int i=20; i>=0; i--) for(int j=20; j>=0; j--) ac[i][j] = ac[i+1][j] + ac[i][j+1] -ac[i+1][j+1] + mp[i][j];
	rep(i,21) rep(j,21) ans += (long long)mp[i][j] * ac[20-i][20-j];
	printf("%lld\n", (ans-ac[10][10])/2);
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define ll long long
#define iof ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897
#define mod 1000000007
#define inf (1ll<<60)
using namespace std;

int main()
{
    iof;
   ll h,w; cin>>h>>w;
   string s[h];
   for(ll i=0;i<h;i++)
    cin>>s[i];

   ll dp[h+1][w+1];
   for(ll i=0;i<=h;i++)
    for(ll j=0;j<=w;j++)
     dp[i][j]=0;
   dp[1][1]=1;
   for(ll i =1;i<=h;i++)
   {
       for(ll j=1;j<=w;j++)
       {
           if(s[i-1][j-1]=='.')
            dp[i][j]+= (dp[i-1][j]+dp[i][j-1])%mod;
       }
   }
   cout<<dp[h][w];
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i= 0;i<N;i++) cin >> A[i];
  int cnt=0;
  while(true){
    bool odd=false;
    for(int i=0;i<N;i++){
      if(A[i]%2 == 1) odd=true;
    }
    if(odd) break;
    for(int i=0;i<N;i++){
      A[i] /=2;
    }
    cnt++;
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double x,y;
    cin>>x>>y;
    int t=1;
    double minx=99999999.9;
    for(int i=1;i<=n;i++)
    {
      double ttt;
      cin>>ttt;
      if(minx>fabs(y-x+ttt*0.006)){
      t=i;
      minx=fabs(y-x+ttt*0.006);
           }
    }
    cout<<t<<endl; 
    return 0;
} 

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char a = s.charAt(0);
		char b = s.charAt(1);
		char c = s.charAt(2);
		int res=0, flag = 0;
		if(a=='R') {
			res=1;
			if(b==a) {
				res++;
				if(c==b)
					res++;
			}
		}
		else {
			if(b=='R') {
				if(b==c)
					res+=2;
				else
					res++;
			}
			else {
				if(c=='R')
					res++;
			}
		}
		System.out.println(res);
		sc.close();

	}
}

Measured memory_bytes: 35540
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,m;
vector<vector<ll>> edge;
vector<ll> dp1;
vector<vector<ll>> dp2;

ll cost(ll a){
    ll ret=0;
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            if((a>>i&1) && (a>>t&1)){ret+=edge[i][t];}
        }
    }
    return ret/2;
}

void build(){
    for(int i=0;i<1LL<<n;i++){
        dp1[i]=cost(i);
    }
}

ll connect(ll w,ll a){
    ll ret=0;
    for(int i=0;i<n;i++){
        if(a>>i&1){ret+=edge[w][i];}
    }
    return ret;
}



int main(){
    ll C=0;
    cin>>n>>m;
    edge.resize(n,vector<ll>(m,0));
    dp1.resize(1LL<<n);
    dp2.resize(1LL<<n,vector<ll>(n,-1));
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--; b--;
        edge[a][b]=c;
        edge[b][a]=c;
        C+=c;
    }
    build();
    dp2[1][0]=0;
    for(int i=1;i<1LL<<n;i++){
        if((i&1)==0){continue;}
        ll k=1LL<<n; k--; k^=i;
        for(int t=0;t<n;t++){
            if(dp2[i][t]==-1){continue;}
            for(ll h=k;h>0;h=(--h)&k){
                dp2[i^h][t]=max(dp2[i^h][t],dp2[i][t]+dp1[h^(1LL<<t)]);
            }
            for(int h=0;h<n;h++){
                if((i>>h&1) || edge[t][h]==0){continue;}
                dp2[i^(1<<h)][h]=max(dp2[i^(1<<h)][h],dp2[i][t]+edge[t][h]);
            }
        }
    }
    cout<<C-dp2[(1LL<<n)-1][n-1]<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 7424
#include <stdio.h>

int main(void) {
  int i, j, a, b;
  while( 1 ) {
    scanf("%d%d", &a, &b);
    if(!a && !b) break;
    a /= 100, b /= 100;
    b -= a;
    int x, y = 0, z;
    x = b / 10;
    b %= 10;
    if(b >= 5) y = 1;
    z = b % 5;
    printf("%d %d %d\n", z, y, x);
  }
  return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")



int main()
{

	int N, K;
	cin >> N >> K;
	map<int, int> G;
	fx(K) {
		int k;
		cin >> k;
		fy(k) {
			int i;
			cin >> i;
			G[i] = 1;
		}
	}
	int ans = 0;
	fx(N) {
		if (G[x+1]==0) {
			ans++;
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 3628
n=int(input())
ans=[0]*4
for i in range(n):
	s=input()
	if s=='AC':
		ans[0]+=1
	elif s=="WA":
		ans[1]+=1
	elif s=="TLE":
		ans[2]+=1
	else:
		ans[3]+=1
print("AC x ",ans[0])
print("WA x ",ans[1])
print("TLE x ",ans[2])
print("RE x ",ans[3])

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);I++) cin >> x[i];

int main(){
  int N,K,X,Y ;
  cin >> N >> K >> X >> Y ;
  if(N <= K)
    cout << N*X << endl;
  else
    cout << (N-K)*Y+K*X <<endl;
}

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

using namespace std;

int main() {
	char t[1123],s[1123];
	int t1,s1, maior=0,aux=0;
	scanf("%s", s);
	scanf("%s", t);
	t1 = strlen(t);
	s1 = strlen(s);

	for (int i = 0;i <= s1 - t1;i++) {
		aux=0;
		for (int j = 0;j < t1;j++) {
			// printf("%d %c %d %c\n", i+j, s[i+j], j, t[j]);
			if (s[i+j] == t[j]){
				aux++;
			}
		}
		// printf("  %d\n", aux);

		if (aux > maior) {
			maior = aux;
		}
	}

	printf("%d\n", t1-maior);

	return 0;
}

Measured memory_bytes: 3820
N = int(input())
arr = []
for i in range(1, N+1):
    if i % 5 == 0 and i % 3 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    arr.append(i)
print(sum(arr))

Measured memory_bytes: 29988
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(), W = sc.nextInt(), N = sc.nextInt();
        sc.nextLine();
        int sx = -1, sy = -1;
        char[][] map = new char[H][W];
        int[][] fac = new int[N][2];
        for (int i = 0; i < H; i++) {
            String line = sc.nextLine();
            for (int j = 0; j < W; j++) {
                map[i][j] = line.charAt(j);
                if (map[i][j] == 'S') {
                    sx = i;
                    sy = j;
                } else if (Character.isDigit(map[i][j])) {
                    int t = map[i][j] - '0';
                    fac[t - 1][0] = i;
                    fac[t - 1][1] = j;
                }
            }
        }
        dis = new int[H][W];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < H; j++) {
                for (int k = 0; k < W; k++) {
                    dis[j][k] = Integer.MAX_VALUE;
                }
            }
            sum += bfs(map, sx, sy, fac[i][0], fac[i][1]);
            sx = fac[i][0];
            sy = fac[i][1];
        }
        System.out.println(sum);

    }

    public static int[][] dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

    public static int[][] dis;

    public static int bfs(char[][] map, int sx, int sy, int ex, int ey) {
        if (sx == ex && sy == ey) return 0;
        Queue<P> queue = new LinkedList<>();
        queue.add(new P(sx, sy));
        dis[sx][sy] = 0;

        while (!queue.isEmpty()) {
            P p = queue.poll();
            if (p.x == ex && p.y == ey) break;
            for (int i = 0; i < 4; i++) {
                int newx = p.x + dir[i][0];
                int newy = p.y + dir[i][1];
                if (newx < 0 || newy < 0 || newx >= map.length || newy >= map[0].length || dis[newx][newy] != Integer.MAX_VALUE || map[newx][newy] == 'X')
                    continue;
                dis[newx][newy] = dis[p.x][p.y] + 1;
                queue.add(new P(newx, newy));
            }
        }
        return dis[ex][ey];

    }

}

class P {
    public P(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int x, y;

}



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

int main(){
	int N , l , r;
  	cin >> N;
  	int answer = 0;
  	for (int i =0; i < N ; i++ ){
      	cin >> l >> r;
  		answer += r - l + 1;
    }
  	cout << answer << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] P = new int[N];
            for (int i = 0; i < N; i++) {
                P[i] = sc.nextInt();
            }

            long ans = 0;
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < N; i++) {
                min = Math.min(min, P[i]);
                if (min >= P[i]) {
                    ans++;
                }
            }

            System.out.println(ans);
        }
    }

}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e5+5;

vector <ll> flag(L);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    string s;
    cin >> s;

    // ll j=1;
    ll cnt1 = 0;
    ll cnt2 = 0;
    for(ll i=0; i<(ll)s.size(); i++)
    {
        if(s[i]=='0')
        {
            cnt1++;
        }

        else
        {
            cnt2++;
        }
    }

    cout << min(cnt1, cnt2)*2 << endl;

    return 0;
}

Measured memory_bytes: 1280
N, K = map(int, input().split())

s = list(range(N + 1))
cumsum = [0] * (N + 1)
for i in range(1, N + 1):
    cumsum[i] = cumsum[i - 1] + s[i]

MOD = 10 ** 9 + 7
ans = 1
for k in range(K, N + 1):
    ans += (cumsum[-1] - cumsum[-k - 1]) - cumsum[k - 1] + 1
print(ans % MOD)


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

using namespace std;

int main() {
    int n;
    cin >> n;
    string str;
    cin >> str;

    string result = str.substr(0, 1);
    for (int i = 0; i < str.length(); i++) {
        string tmp = str.substr(i, 1);
        if (result.substr(result.length() - 1, 1) != tmp) {
            result += tmp;
        }
    }

    cout << result.length() << endl;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  cout << "Christmas";
  for(i = 0; i < 25 - n; i++)
    cout << " Eve";
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
import collections
d=collections.defaultdict(int)
n=int(input())
s=input()
def f(s,r,b,t):
    if t==n:
        d[(r,b)]+=1
        return
    f(s,r+s[t],b,t+1)
    f(s,r,b+s[t],t+1)
f(s[:n],"","",0)
d1=d
d=collections.defaultdict(int)
f(s[-1:n-1:-1],"","",0)
ans=0
for i,j in d.items():
    ans+=j*d1[i]
print(ans)

Measured memory_bytes: 150520
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int outlet = 1;
		int ans=0;
		while(outlet<b) {
			--outlet;
			outlet+=a;
			++ans;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22740
import numpy as np

n,m = map(int,input().split())
h=list(map(int,input().split()))

l=[0]*n
for i in range(m):
    x,y=map(int,input().split())
    if h[x-1]<=h[y-1]:
        l[x-1]=1
    if h[x-1]>=h[y-1]:
        l[y-1]=1

count=0
for i in range(n):
    if l[i]==0:
        count+=1

print(count)

Measured memory_bytes: 38520
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
S = sum(A) % MOD
ans = (S ** 2) % MOD
for a in A:
    ans -= a**2
    ans %= MOD

ans *= pow(2, MOD-2, MOD)
ans %= MOD
print(ans)

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

ls = [0]*N

count = 0
now = 0
roop = 0

while ls[now] == 0 and count < K:
    ls[now] = 1
    now = A[now] - 1
    count += 1
k = K - count
if k > 0:
    while ls[now] == 1:
        ls[now] = 2
        now = A[now] - 1
        roop += 1

    k = k%roop

    while k > 0:
        now = A[now]-1
        k -= 1

print(now+1)


Measured memory_bytes: 32304
#include <iostream>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

typedef pair<int,int> pint;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
string mp[1000];
int visit[1000][1000];

int main(){
    int h,w,n,cx,cy,ans=0;
    cin>>h>>w>>n;
    for(int i=0;i<h;++i){
        cin>>mp[i];
        if(mp[i].find('S')!=string::npos){
            cy=i;cx=mp[i].find('S');
        }
    }    
    for(int i=1;i<=n;++i){
        memset(visit,0,sizeof(visit));
        visit[cy][cx]=1;
        queue<pint> q;
        q.push(make_pair(cx,cy));
        while(!q.empty()){
            pint pi=q.front();q.pop();
            cx=pi.first;cy=pi.second;
            int vc=visit[cy][cx];
            if(mp[cy][cx]==i+'0'){
                ans+=vc-1;break;
            }
            for(int j=0;j<4;++j){
                int tx=cx+dx[j];int ty=cy+dy[j];
                if(tx>=0&&ty>=0&&tx<w&&ty<h&&visit[ty][tx]==0&&mp[ty][tx]!='X'){
                    q.push(make_pair(tx,ty));
                    visit[ty][tx]=vc+1;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7984
n,k = map(int,input().split())
s = 'R' + input() + 'L'

score = 0
for i in range(1,n+1):
  if s[i] == 'R' and s[i+1] =='R':
    score += 1
  elif s[i] =='L' and s[i-1]=='L':
    score += 1
print(min(n-1,score+2*k))
    

Measured memory_bytes: 3316
#include<stdio.h>

int main(void){
       int x,y;
       scanf("%d %d",&x,&y);

       if((4*x-y)%2==0 && (2*x-y)%2==0 && (4*x-y)>=0 && (2*x-y)<=0){
              printf("Yes");
       }
       else{
              printf("No");
       }
       return 0;
}

Measured memory_bytes: 1736
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string C1 = Console.ReadLine();
            string C2 = Console.ReadLine();
            if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0])
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13140
n = int(input().split()[0])
c = list(map(int,input().split()))
dp = list(range(n+1))

for i in range(2,n+1):
    for j in c:
        if j <= i and dp[i-j] + 1 < dp[i]:
            dp[i] = dp[i-j]+1

print(dp[n])

Measured memory_bytes: 7512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
 
using namespace std;
 
int main(){
    string s;
    cin >> s;
    vector<char> vec(s.length());
    rep(i,s.length()) vec[i] = s[i];
    for (char c='a';c<='z';c++){
        int cnt = count(all(vec),c);
        if (cnt>=2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long i = 1;
        long sum = 0;

        while(i <= N){
            if(((i % 3) == 0) && ((i % 5) == 0)){
            }
            else if(i % 5 == 0){
            }
            else if(i % 3 == 0){

            }else{
                //System.out.println(i);
                sum += i;
                
            }
            i++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    if (N % 10 == 3) cout << "bon" << endl;
    else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    string s;
    cin>>s;
    int cnt=0;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='1')cnt++;
    }
    int c=s.size()-cnt;
    cout<<2*min(cnt,c)<<endl;

    return 0;
}





Measured memory_bytes: 592
package main

import (
	"fmt"
)

const mod = 1e9+7

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	
	a := make([]int, m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}

	oks := make([]bool, n+1)
	j := 0
	for i:=0;i<n+1;i++ {
		if j < m && i == a[j] {
			oks[i] = true
			j++
		} else {
			oks[i] = false
		}	
	}
	
	dp := make([]int, n+1)
	dp[0] = 1
	if oks[1] {
		dp[1] = 0
	} else {
		dp[1] = 1
	}
	for i:=2;i<n+1;i++{
		if !(oks[i]) {
			dp[i] = dp[i-2]+dp[i-1]
			dp[i]%=mod
		} else {
			dp[i] = 0
		}
	}
	fmt.Println(dp[n]%mod)
}

Measured memory_bytes: 5504
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S[] = sc.next().split("/");

        int year = Integer.parseInt(S[0]);
        int month = Integer.parseInt(S[1]);

        String ans = "TBD";
        if(year < 2019 || (year == 2019 && month < 5)){
            ans = "Heisei";
        }

        out.println(ans);
    }
}


Measured memory_bytes: 21204
from collections import deque

s = deque(input())
q = int(input())

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

Measured memory_bytes: 44524
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
import bisect

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_cum = [0]*(N+1)
B_cum = [0]*(M+1)
for i in range(N):
    A_cum[i+1] = A_cum[i]+A[i]
for i in range(M):
    B_cum[i+1] = B_cum[i]+B[i]

ans = 0
for i in range(N+1):
    num_A = i
    time = K - A_cum[i]
    if time<0:
        continue
    num_B = bisect.bisect_right(B_cum, time)
    num_B = max(0, num_B-1)
    ans = max(ans, num_A + num_B)
print(ans)

Measured memory_bytes: 110184
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        b = list(set(a))
        c = []
        for i in b:
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3 and b[0]^b[1]^b[2] == 0:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 60784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
//#define coutyn(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    Graph g(n + 1);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, -1);
    vector<int> pre(n, -1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty())
    {
        int v = q.front();q.pop();
        for(auto it : g[v])
        {
            if (dist[it] != -1) continue;
            dist[it] = dist[v] + 1;
            pre[it] = v;
            q.push(it);
        }
    }

    cout << "Yes" << endl;
    Rep(i, 1, n)
    {
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10708
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int K;
	cin >> K;
	if (K % 2 == 0) {
		cout << -1;
		return 0;
	}
	
	int num = 0;
	for (int i = 1; i <= 10000000; i++) {
		num = num * 10 + 7;
		num %= K;
		if (num == 0) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}

Measured memory_bytes: 3632
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
while(a>0 && c>0)
{
	a=a-d;
	c=c-b;

}
if(c<=0)
System.out.println("Yes");
else
System.out.println("No");
}}

Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;


int solve(){
    int k;
    cin>> k;
    int res = 0;
    rep(i, 0, k + 1){
        res = (res*10 + 7)%k;
        if(res == 0)
            return cout<< (i+1), 0;
    }
    cout<< "-1";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;

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

    int n;
    cin >> n;

    int cur = 0;
    bool flag = false;

    for (int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        if (x == y) cur++;
        else cur = 0;
        if (cur == 3) flag = true;
    }
    cout << (flag ? "Yes" : "No") << "\n";
}


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


//node
typedef struct DATA{
  int key;
  struct DATA *prev;
  struct DATA *next;
}DATA;


//prototype
void insert(int);
void delete(DATA *);
void print_node(void);


//head set
DATA *head,*tail;


int main(){
  int num, key, i;
  char com[15];
  DATA *dp;
  
  //create head
  head=(DATA *)malloc(sizeof(DATA));
  head->next=NULL;
  head->prev=NULL;

  //input num
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    
    //input command
    scanf("%s",com);
      
    //insert data
    if(strcmp(com,"insert")==0){
      //input key
      scanf("%d",&key);
      
      insert(key);
    }

    //delete data
    else if(strcmp(com,"delete")==0){
      //input key
      scanf("%d",&key);

      for(dp=head->next;dp!=NULL;dp=dp->next){
	if(dp->key==key) {
	  delete(dp);
	  break;
	}
      }
    }

    //deleteFirst
    else if(strcmp(com,"deleteFirst")==0) delete(head->next);

    //deleteLast
    else if(strcmp(com,"deleteLast")==0) delete(tail);
    
    //command error
    else printf("ERROR:command\n");

     
  }

  //output node
  print_node();

  free(head);
  return 0;
}


//insert to next head
void insert(int key){
  DATA *data;
  
  data=(DATA *)malloc(sizeof(DATA));

  if(data==NULL) return;

  data->key=key;
  
  data->next=head->next;
  if(data->next!=NULL)data->next->prev=data;
  else tail=data;
  head->next=data;
  data->prev=head;

}


//delete DATA *
void delete(DATA *dp){
  
  dp->prev->next=dp->next;
  if(dp->next!=NULL)  dp->next->prev=dp->prev;
  else  tail=dp->prev;

  free(dp);
}


//output node
void print_node(void){
  DATA *dp;

  for(dp=head->next;dp->next!=NULL;dp=dp->next){
    printf("%d ",dp->key);
  }
  printf("%d\n",dp->key);
}



Measured memory_bytes: 32980
n, ww = map(int, input().split())
w, v = [0] * n, [0] * n
for i in range(n):
    w[i], v[i] = map(int, input().split())

x = float("inf")

dp = [[x] * (100100) for i in range(110)]

dp[0][0] = 0
for i in range(n):
    for j in range(100100):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
        
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = 0
for i in range(100100):
    if dp[n][i] <= ww:
        ans = i

print(ans)

Measured memory_bytes: 313368
n, m = [int(i) for i in input().split()]
i = 0
j = 1
k = 0
while j < n//2 and k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1
i = (i + j - 1 + (m - k)) % n
j = 2
while k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1


Measured memory_bytes: 70180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(){
    unsigned long long sum=0,n,k,i;
    char token[1000]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(strtok(token, " "));k=atoi(strtok(NULL, " "));
    for (i=k; i<=n+1; i++){
    	sum=(sum+(n*i-i*(i-1)+1))%1000000007;
    }
    printf("%lld",sum);
    return 0;
}

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

long long n, w, i, j, k, mx = 0, dp[2][100019] = { };
vector<pair<long long, long long>> items;
//w - v
int main() {
	cin >> n >> w;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 100019; j++)
			dp[i][j] = 1000000007;
	items.resize(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> items[i].first >> items[i].second;

	dp[0][0] = 0;
	dp[1][0] = 0;
	for (int it = 1; it <= n; it++) {
		i = it & 1;
		for (int j = 1; j <= n * 1000; j++) {
			if (items[it].second > j) {
				dp[i][j] = dp[i ^ 1][j];
			} else {
				dp[i][j] = min(dp[i ^ 1][j], dp[i ^ 1][j - items[it].second] + items[it].first);
			}
			if(dp[i][j] <= w && j > mx)
				mx = j;
		}
		cout << "\n";
	}

	cout <<  mx;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

int lowerbound (int k, vector& v) {
  return v[k-1];
}

int main() {
  int n; input >> n;
  vector start (n);
  vector end (n);
  for (int i=0; i<n; i++) {
	int a, b; input >> a >> b;
	start[i] = a; end[i] = b;
  }
  std::sort (start.begin(), start.end());
  std::sort (end.begin(), end.end());

  if (n % 2 != 0) {
	// n is odd
	int lambda = n/2;
	int atleast = end[lambda];
	int atmost = start[lambda];
	std::cout << atleast - atmost + 1 << std::endl;
  }
  else {
	// n is even
	int l1 = start[n/2-1];
	int r1 = end[n/2-1];
	int l2 = start[n/2];
	int r2 = end[n/2];
	int mr = (r1+r2);
	int ml = (l1+l2);
	std::cout << mr-ml+1 << std::endl;
  }
}



Measured memory_bytes: 4768
n = gets.to_i
frases = []
n.times do
  s, t, u = gets.split.map(&:to_i)
  (s..t).each do |i|
    frases << [i, u]
  end
end
m = gets.to_i
melodies = []
maxm = 0
m.times do
  t = gets.to_i
  melodies << t
  maxm = t if maxm < t
end

dp = Array.new(maxm + 1, -1)
dp[0] = 0
frases.each_with_index do |v, j|
  v[0].upto(maxm) do |i|
    if dp[i - v[0]] != -1 && dp[i] < dp[i - v[0]] + v[1]
      dp[i] = dp[i - v[0]] + v[1]
    end
  end
end

ans = []
melodies.each do |melody|
  if dp[melody] != -1
    ans << dp[melody]
  else
    puts -1
    exit
  end
end
ans.each do |a|
  puts a
end


Measured memory_bytes: 14400
n = int(input())
lis = list(map(int, input().split()))
val = [0] * n

for i in range(n, 0, -1):
    if n // i == 1:
        val[i - 1] = lis[i - 1]
    else:
        p = n // i
        a = 0
        for j in range(p):
            a += val[i * (j + 1) - 1]
        if a % 2 == lis[i - 1]:
            val[i - 1] = 0
        else:
            val[i - 1] = 1

t = sum(val) % 2
if lis[0] == t:
    print(sum(val))
    print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
else:
    print(-1)
    

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

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    vector<int> check(N,N);
    for(int i=0; i<N; i++) cin>>A[i];

    for(int i=0; i<K; i++){
        vector<int> tmp(N,0);
        for(int j=0; j<N; j++){
            int left = max(0,j-A[j]);
            int right = min(N-1,j+A[j]);
            tmp[left]++;
            if(right + 1 < N) tmp[right+1]--;
        }

        for(int j=1; j<N; j++){
            tmp[j] += tmp[j-1];
        }

        A = tmp;
        if(A == check) break; 
    }

    for(int i=0; i<N; i++) cout<<A[i]<<" ";
    cout<<endl;

    return 0;
}

Measured memory_bytes: 5632
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));


class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  getDepth() {
    return this.parent ? this.parent.getDepth() + 1 : 0;
  }
  add(node) {
    node.parent = this;
    this.children.push(node);
  }
  getType() {
    if (this.getDepth() === 0) {
      return 'root';
    }
    return this.children.length ? 'internal node' : 'leaf';
  }
  toString() {
    return 'node ' + this.id + ': ' + [
      'parent = ' + (this.parent ? this.parent.id : -1),
      'depth = ' + this.getDepth(),
      this.getType(),
      '[' + this.children.map(node => node.id).join(', ') + ']',
    ].join(', ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    if (!this.map.has(id)) {
      this.map.set(id, new Node(id));
    }
    return this.map.get(id);
  }
  print() {
    for (let i = 0; i < this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([id, k, ...ck]) => {
  const parent = tree.getNode(id);
  ck.forEach(c => {
    const node = tree.getNode(c);
    parent.add(node);
  });
});

tree.print();



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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

const int INFTY=1<<29;

int main()
{
	for(int h,w;cin>>h>>w,h|w;){
		int n=h*w;
		vvi dist(n,vi(n,INFTY));
		vi hearts;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				int x; cin>>x;
				if(x==1)
					hearts.push_back(i*w+j);
				
				dist[i*w+j][i*w+j]=0;
				int di[]={-1,1,0,0},dj[]={0,0,-1,1};
				for(int k=0;k<4;k++){
					int ii=i+di[k],jj=j+dj[k];
					if(0<=ii && ii<h && 0<=jj && jj<w)
						dist[i*w+j][ii*w+jj]=dist[ii*w+jj][i*w+j]=1;
				}
			}
		}
		
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		
		int hsize=hearts.size();
		vvi dp(1<<hsize,vi(n,INFTY));
		for(int i=0;i<hsize;i++)
			for(int j=0;j<n;j++)
				dp[1<<i][j]=dist[hearts[i]][j];
		
		for(int i=0;i<(1<<hsize);i++){
			for(int j=i;j;j=(j-1)&i)
				for(int k=0;k<n;k++)
					dp[i][k]=min(dp[i][k],dp[j][k]+dp[i^j][k]);
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
					dp[i][j]=min(dp[i][j],dp[i][k]+dist[k][j]);
		}
		
		int res=INFTY;
		for(int i=0;i<n;i++)
			res=min(res,dp[(1<<hsize)-1][i]);
		cout<<n-(res+1)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#pragma GCC diagnostic error "-std=c++11"
using namespace std;
int a[22],b[22];
int main(){
	int n,i,j;
	cin>>n;
	long long ans=0;
	for(i=1;i<=n;++i) cin>>a[i];
	for(i=1;i<=n;++i) cin>>b[i],ans+=max(0,a[i]-b[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;


int main(void)
{
	char s[200000+2], t[200000+2];

	while(scanf("%[a-z]\n%[a-z]\n", s, t)==2)
	{
		vi table(256);
		int l=strlen(s);
		int ans=1;
		vi fs(256), ft(256);
		int cs=0, ct=0;

		for(int i=0;i<l;i++)
		{
			if(fs[s[i]]==0) cs++,fs[s[i]]++;
			if(ft[t[i]]==0) ct++,ft[t[i]]++;
			
			if(table[s[i]]==0)
			{
				table[s[i]]=t[i];
			}
			else
			{
				if(table[s[i]]!=t[i])
				{
					ans=0;
					break;
				}
			}
		}
		if(cs!=ct) ans=0;
//		printf("cs=%d  ct=%d\n", cs ,ct);
		printf("%s\n", ans?"Yes":"No");
	}

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

        signed main() {
    cout<<fixed<<setprecision(10);
        string s,t;
        cin>>s;
        int k;
        cin>>k;
        priority_queue<string,vector<string> , greater<string>> que;
        for(int i=0;i<s.size();i++){
                for(int j=1;i+j<=s.size()&&j<=5;j++){
                    string    k(s,i,j);
                        que.push(k);
                }
        }
     t=que.top();
       que.pop();
        k--;
        while(k){
                while(que.top()==t)que.pop();
                t=que.top();
                que.pop();
                k--;
        }

        cout<<t;
       

        }


Measured memory_bytes: 1660
#include <stdio.h>

int main(void) {
	static const char yes[256] = {
		['A'] = 1, ['C'] = 1, ['G'] = 1, ['T'] = 1
	};
	char S[16];
	int i;
	int mizukinana = 0, fukuennmisato = 0;
	if (scanf("%15s", S) != 1) return 1;
	for (i = 0; ; i++) {
		if (yes[(unsigned char)S[i]]) {
			fukuennmisato++;
		} else {
			if (mizukinana < fukuennmisato) mizukinana = fukuennmisato;
			fukuennmisato = 0;
		}
		if (S[i] == '\0') break;
	}
	printf("%d\n", mizukinana);
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n,m;
  cin >> n >> m;
  
  if(abs(n-m) >= 2){
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = 1;
  if(abs(n-m) == 1){
    REP(i,n){
      ans *= (i+1);
      ans %= MOD;
    }
    REP(i,m){
      ans *= (i+1);
      ans %= MOD;
    }
  }
  
  else{
    ans = 2;
        REP(i,n){
      ans *= (i+1);
      ans %= MOD;
    }
        REP(i,m){
      ans *= (i+1);
      ans %= MOD;
    }
  }
  
  cout << ans << endl;


 return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <cmath>
#include <deque>
 
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
vector<pii> G[MAXN];
bool visit[MAXN];
int dis[MAXN];
 
bool dfs(int cur, int ds) {
     visit[cur] = 1;
     dis[cur] = ds;
     bool OK = true;
     for (auto i : G[cur]) {
         int to = i.first;
         int w = i.second;
         if (visit[to] && dis[to] != dis[cur] + w) {
            // printf("cur = %d to = %d dis[to] = %d outw = %d\n", cur, to, dis[to], dis[cur] + w);
            OK = false;
         }
         else if (!visit[to] && !dfs(to, dis[cur] + w)) OK = false;
     }
     return OK;
}
 
 
int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int x, y, d;
        scanf("%d %d %d", &x, &y, &d);
        G[x].push_back(make_pair(y, d));
        G[y].push_back(make_pair(x, -d));
    }
    bool OK = true;
    for (int i = 1; i <= N; i++) {
        if (!visit[i] && !dfs(i, 0)) OK = false;
    }
    puts(OK ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <algorithm>
#define INF 1e9

using namespace std;

int main() {
    int n, tl, ans = INF;
    cin >> n >> tl;
    for (int i = 0; i < n; ++i) {
        int c, t;
        cin >> c >> t;
        if (t <= tl) ans = min(ans, c);
    }
    if (ans == 1e9) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

typedef struct node {
	int key;
	struct node *p_left;
	struct node *p_right;
	struct node *p_parent;
}NODE;

void insert(int value);	/* ?????\ */
void inorder(NODE *p_node);	/* ??????????????? */
void preorder(NODE *p_node); /* ??????????????? */

NODE *p_root;

int main(void) {

	char command[20];
	int value;
	int n;
	int i;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", &command);
		if (command[0] == 'i') {
			scanf("%d", &value);
			insert(value);
		}
		else if (command[0] == 'p') {
			inorder(p_root);
			printf("\n");
			preorder(p_root);
			printf("\n");
		}
	}
	return 0;
}

void insert(int value) {
	NODE *x = p_root;	/* ??? */
	NODE *y = NULL;	/* x?????? */

	NODE *z = (NODE *)malloc(sizeof(NODE));
	z->key = value;
	z->p_left = NULL;
	z->p_right = NULL;

	while (x != NULL) {
		y = x;
		if (z->key < x->key) {
			x = x->p_left;		/* ?????????????§???? */
		}
		else {
			x = x->p_right;	/* ?????????????§???? */
		}
	}
	z->p_parent = y;

	if (y == NULL) {	/* ??¨???????????´??? */
		p_root = z;
	}
	else if (z->key < y->key) {
		y->p_left = z;	//z?????????????????????
	}
	else {
		y->p_right = z;	//z?????????????????????
	}
}

//?????????????????§??¨???
void inorder(NODE *p_node) {

	if (p_node == NULL) {
		return;
	}
	inorder(p_node->p_left);
	printf(" %d", p_node->key);
	inorder(p_node->p_right);
}

//?????????????????§??¨???
void preorder(NODE *p_node) {

	if (p_node == NULL) {
		return;
	}
	printf(" %d", p_node->key);
	preorder(p_node->p_left);
	preorder(p_node->p_right);
}

Measured memory_bytes: 24040