akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    int mn = min({a, b, c});
    int mx = max({a, b, c});
    int mid = a+b+c - mn - mx;

    int ans = 0;
    int mn_dif = mx - mn;
    int mid_dif = mx - mid;

    if((mn_dif - mid_dif) % 2 == 0){
        ans += (mn_dif - mid_dif) / 2;
        ans += mid_dif;
    }
    else{
        ans += (mn_dif - mid_dif) / 2;
        ans += mid_dif;
        ans += 2;
    }
    cout << ans << endl;

    return 0;
}


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

zero_index_left = []
flag = False
for i in range(N):
    if flag is False and S[i] == "0":
        zero_index_left.append(i)
        flag = True
    elif S[i] == "1":
        flag = False

if K >= len(zero_index_left):
    print(N)
    exit()
    
zero_index_right = []
S = S[:: -1]
flag = False
for i in range(N):
    if flag is False and S[i] == "0":
        zero_index_right.append(i)
        flag = True
    elif S[i] == "1":
        flag = False
        
ans = 0
for i in range(len(zero_index_left) - K):
    if i == 0:
        ans = max(ans, zero_index_left[i + K])
        ans = max(ans, zero_index_right[i + K])
    else:
        ans = max(ans, zero_index_left[i + K] - N + 1 + zero_index_right[-i] - 1)
        ans = max(ans, zero_index_right[i + K] - N + 1 + zero_index_left[-i] - 1)
print(ans)

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

#define ll                 long long
#define mod                1000000007
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define T(t)               cout << "Case " << t <<": ";
#define scan(v)            for(int i = 0; i<n; i++){ll x;cin>>x;v.pb(x);}
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL);

ll a[2000005];

int main() {
     
       #ifndef ONLINE_JUDGE
       //freopen("read.txt","r",stdin);
      // freopen("write.txt","w",stdout);
       #endif

       ll x, n;
       cin >> x >> n ;
       set < ll > s;
       ll mx = 0;
       for( int i = 0 ; i < n ; i++ ){
              cin >> a[i];
              s.insert(a[i]);
       }

       if( n == 0 ){
              cout << x << endl;
              return 0;
       }

       ll mn = 1e9;
       ll ans ;
       for( int i = 0 ; i <= 105 ; i++ ){
             if( abs(i - x ) < mn && !s.count(i)){
                    mn = abs(x-i);
                    ans = i ;
                   
             }
       }
       cout << ans << endl;

     

       
       
      

       




       return 0;

}

Measured memory_bytes: 3656
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LIR(n)
    p.sort(key = lambda x:math.atan2(x[1],x[0]))
    p += p
    ans = 0
    for i in range(n):
        m = [0,0]
        for j in range(i,i+n):
            m[0] += p[j][0]
            m[1] += p[j][1]
            d = m[0]**2+m[1]**2
            if ans < d:
                ans = d
    print(ans**0.5)
    return

#Solve
if __name__ == "__main__":
    solve()


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

typedef unsigned long long  ULL;
typedef long long LL;

#define pb push_back
#define mp make_pair
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
//    cin>>T;
    T=1;
    while(T--){
       
       ULL n,k;
       cin>>n>>k;
       
       ULL r= n%k;
       ULL p;
       if(r>k) p=r-k;
       else p=k-r;
       if(r<p) cout<<r;
       else  cout<<p;
       
       
       
    }
    
    return 0;
}

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

typedef long long ll;

ll R;
int main() {
  for (ll i = 0; i < 5; ++i) {
    ll x;
    cin >> x;
    if (x == 0) R = i;
  }
  cout << R + 1 << endl;
  return 0;
}


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

using namespace std;

#define inf (ll)1e18
#define ll long long
#define all(x) x.begin(), x.end()
#define X first
#define Y second

const int N = 1000060;

const int mod = (int)1e9 + 7;
const int MX = 1000020;


int main(){

    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;

    int tmp = n;
    int res = 0;
    while(tmp){
    	int c = tmp % 10;
    	res += c;
    	tmp /= 10;
    }

    if(n % res == 0){
    	cout << "Yes" << endl;
    }
    else
    	cout << "No" << endl;

    return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
	char s[100],p[100],scopy[202];
	scanf("%s",s);
	scanf("%s",p);
	strcpy(scopy,s);
	strcat(scopy,s);
	if(strstr(scopy,p)==NULL)cout << "No\n";
	else cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 3168
#include <stdio.h>
int main(void){
	int a,b[10000],i,j;
	int c=1000000;
	int d=-1000000;
	unsigned long long int e=0;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<a;i++){
		if(b[i]<c){
			c=b[i];
		}
		if(b[i]>d){
			d=b[i];
		}
		e = e + b[i];
	}
	printf("%d %d %lld\n",c,d,e);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


const int lim = 100100;
int n,m;
vector<PII> G[lim];
bool visited[lim];
int x[lim];

bool dfs(int p){
  visited[p] = true;
  for(auto &t : G[p]){
    if(visited[t.first]){
      if(x[t.first] != x[p]+t.second) return false;
      continue;
    }else{
      x[t.first] = x[p]+t.second;
      if(!dfs(t.first)) return false;
    }
  }
  return true;
}

signed main(){
  cin>>n>>m;
  rep(i,m){
    int l,r,d; cin>>l>>r>>d; l--; r--;
    G[l].PB({r,d}); G[r].PB({l,-d});
  }
  reps(i,n){
    if(visited[i]) continue;
    if(!dfs(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main(){
  int n,s=0; cin >>n;
  vector<int>a(n-1);
  for(int i=0; i<n-1; i++){cin >>a[i];}
  for(int i=0; i<n-2; i++){s+=min(a[i],a[i+1]);}
  s+=a[0]+a[n-2];
  cout <<s;
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 REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main(){
	int h,w;
	cin >> h >> w;
	char field[55][55];
	rep(i,h+2)rep(j,w+2)field[i][j] = '.';
	REP(i,h)REP(j,w) cin >> field[i][j];
	
	bool ok = true;
	REP(i,h){
		REP(j,w){
			bool flag = false;
			if(field[i][j] == '#'){
				rep(k,4){
					int ny = i + dy[k];
					int nx = j + dx[k];
					if(field[ny][nx] == '#')flag = true;
				}
				if(flag == false) ok = false;
			}
		}
	}
	if(ok){
		cout << "Yes" << endl;
	} else{
		cout << "No" << endl;
	}
    return 0;
}



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

int mod_num = 1e9 + 7;

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< int > A(N);
    for(long long i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    int down = 0;
    int up = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(A[i] > A[j]){
                down++;
            }
        }
        for(int j=i-1; j>=0; j--){
            if(A[i] > A[j]){
                up++;
            }
        }
    }
    
    int cnt = 0;
    long long tmp = ( (long long)K * ((long long)K + 1) / (long long)2 ) % mod_num;
    tmp = (tmp * down) % mod_num;
    cnt += tmp;
    
    tmp = ( (long long)K * ((long long)K - 1) / (long long)2 ) % mod_num;
    tmp = (tmp * up) % mod_num;
    cnt += tmp;
    cnt = cnt % mod_num;
    
    std::cout << cnt << std::endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cfloat>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
const int mod = 1e9+7;
const int INFINT = INT_MAX/2;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for (int i=0;i<N;i++){
        cin >> x[i];
    }
    ull dp[N+1][N+1][50*50+1];
    for (int i=0;i<N+1;i++){
        for (int j=0;j<N+1;j++){
            for (int k=0;k<50*N+1;k++){
                if(i==0 && j==0 && k == 0){
                    dp[i][j][k] = 1;
                }else if(i>=1 && k < x[i-1]){
                    dp[i][j][k] = dp[i-1][j][k];
                }else if(i>=1 && j>=1 && k >= x[i-1]){
                    dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
                }else{
                    dp[i][j][k] = 0;
                }
            }
        }
    }
    ull res = 0ull;
    for (int i=1;i<N+1;i++){
        res += dp[N][i][A*i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string print[]={"No","Yes"};
ll solve(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    if(b>a)return 0;
    if(b>d)return 0;

    ll g=__gcd(b,d);
    ll mn = a - (a-c-1)/g*g - b;
    return mn>=0;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t;cin>>t;
    while(t--)cout<<print[solve()]<<"\n";
}




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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> A(N+1);
  vector<int> ten(N+1);
  vector<int> ch(N+2);
  ten.at(0)=1;
  for(int i=0;i<N;i++){
    A.at(i+1) = A.at(i) + (S[N-i-1]-'0')*ten.at(i);
    A.at(i+1) %= 2019;
    ten.at(i+1)=ten.at(i)*10%2019;
  }
  int s=0;
  for(int i=0;i<N-3;i++){
    if(ch.at(i))
      continue;
    vector<int> a;
    for(int j=i+4;j<=N;j++){
      if((A.at(j)-A.at(i)) % 2019 == 0) {
        s++;
        ch.at(j)=1;
        j+=3;
        a.push_back(j);
      }
    }
    int b=a.size();
    s += b*(b-1)/2;
  }
  cout << s << endl;
}




Measured memory_bytes: 6000
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

#include <bits/stdc++.h>
using namespace std;






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

    string s1, s2;
    cin >> s1 >> s2;
    int res = 0;

    for (int i = 0; i < 3; i++) {
    	if (s1[i] == s2[i]) res++;
    }

    cout << res;

    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  int l = 0, r = 1001001001;
  while (r - l > 1) {
    int c = (l + r) / 2;
    long long cnt = 0;
    for (int i : a) cnt += (i - 1) / c;
    (cnt <= k ? r : l) = c;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3900
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(true){
            int n = in.nextInt();
            if(n==0)break;
            List<syain> list = new ArrayList<syain>();
            Map<Integer,Integer> map = new HashMap<Integer,Integer>();
            int cnt = 0;
            for(int s=0;s<n;s++){
                int ban = in.nextInt();
                if(!map.containsKey(ban)){
                    list.add(new syain(ban));
                    map.put(ban,cnt);
                    cnt++;
                }
                list.get(map.get(ban)).plus(in.nextLong()*in.nextLong());
            }
            boolean sw = false;
            for(int i=0;i<list.size();i++)if(list.get(i).kin>=1000000){
                System.out.println(list.get(i).ban);
                sw=true;
            }
            if(!sw)System.out.println("NA");
        }
    }
}
class syain implements Comparable<syain>{
    int ban;
    long  kin;
    syain(int ban){
        this.ban=ban;
        kin=0;
    }
    public void plus(long kin){
        this.kin+=kin;
    }
    public int compareTo(syain o) {
        return 0;
    }
}

Measured memory_bytes: 25392
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int>A(N);
  cin>>A;

  map<Int, Int> cnt;
  for(Int i=0;i<N;i++) cnt[i - A[i]]++;
  //prArr(cnt);
  Int ans = 0;
  for(Int i=0;i<N;i++){
    cnt[i - A[i]]--;
    Int x = A[i];
    Int score = cnt[x+i];
    //pr(i, x, score);
    ans += score;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 27412
#include <iostream>
#include <vector>
#include <set>

int main(){
  int N;
  std::cin >> N;
  std::multiset<long long> s;
  for(int i = 0; i < (1<<N); i++){
    long long si;
    std::cin >> si;
    s.insert(-si);
  }
  std::vector<long long> t;
  t.push_back(*s.begin());
  s.erase(s.begin());
  for(int i = 0; i < N; i++){
    for(int j = 0; j < (1<<i); j++){
      auto it = s.upper_bound(t[j]);
      if(it == s.end()){
        std::cout << "No" << std::endl;
        return 0;
      }
      t.push_back(*it);
      s.erase(it);
    }
  }
  std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 14712
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
	  public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
	 
	    int n = sc.nextInt(); //県の数
	    int m = sc.nextInt(); //市の数
	    Map<Integer,int[]> map = new TreeMap<Integer,int[]>();
	 
	    for(int i=0; i<m; i++){
	        int[] array = new int[2];
	        array[0] = i;
	        array[1] = sc.nextInt(); //県番号
	        int b = sc.nextInt(); //誕生年
	        map.put(b,array);
	    }
	    int[] ary = new int[n]; //県の数を格納
	    String[] s = new String[m]; //IDを格納
	 
	    for(int[] num :map.values()){
	      ary[num[1]-1]++;
	      s[num[0]] = String.format("%06d%06d",num[1],ary[num[1]-1]);
	    }
	    
	    for(String a: s) {
	    	System.out.println(a);
	    }
	  }
}


Measured memory_bytes: 161748
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int N, M, W, T;
const int MAX = 8;
const int MAXW = 11111;
string S[MAX];
int V[MAX], P[MAX];
int X[MAX], Y[MAX], L[MAX];
int R[MAX][MAX], Q[MAX][MAX];
ll dp[MAXW];

const int INF = 1e9;
int minTime[1 << MAX];
namespace TSP {
	int dp[1 << MAX][MAX];
	int dfs(int state, int now, int all) {
		int& ret = dp[state][now];
		if (ret >= 0) return ret;
		ret = INF;
		if (state == all) return ret = abs(X[now]) + abs(Y[now]);
		for (int i = 0; i < N; i++) if ((all >> i) & 1) {
			if ((state >> i) & 1) continue;
			ret = min(ret, abs(X[now] - X[i]) + abs(Y[now] - Y[i]) + dfs(state | (1 << i), i, all));
		}
		return ret;
	}
}

int best[1 << MAX];
namespace Item {
	ll dp[MAXW];
	ll calc(int state, int M, int W, vi costs) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < M; i++) {
			if ((state>>i)&1) {
				for (int j = 0; j+V[i] <= W; j++) {
					dp[j+V[i]] = max(dp[j+V[i]], dp[j] + P[i]-costs[i]);
				}
			}
		}
		ll ans = 0;
		for (int i = 0; i <= W; i++)
			ans = max(ans, dp[i]);
		return ans;
	}
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	cin >> N >> M >> W >> T;
	for (int i = 0; i < M; i++) {
		cin >> S[i] >> V[i] >> P[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> L[i] >> X[i] >> Y[i];
		for (int j = 0; j < L[i]; j++) {
			string s;
			cin >> s >> Q[i][j];
			for (int k = 0; k < M; k++) {
				if (S[k] == s) R[i][j] = k;
			}
		}
	}
	// ??????????????????????¨???????????????????????????????????°?????????????????±???????
	for (int s = 1; s < 1 << N; s++) {
		memset(TSP::dp, -1, sizeof(TSP::dp));
		int mini = INF;
		for (int i = 0; i < N; i++) if ((s >> i) & 1) {
			mini = min(mini, abs(X[i]) + abs(Y[i]) + TSP::dfs(1 << i, i, s));
		}
		minTime[s] = mini;
	}
	map<int, ll> mp;
	for (int s = 1; s < 1<<N; s++) {
		if (minTime[s] > T) continue;
		// ?????????????¨?????????§??????????????¢??????????????????
		int item = 0;
		vector<int> unko(M, INF);
		for (int j = 0; j < N; j++) if ((s>>j)&1) {
			for (int k = 0; k < L[j]; k++) {
				int l = R[j][k];
				item |= 1<<l;
				unko[l] = min(unko[l], Q[j][k]);
			}
		}
		ll tmp = Item::calc(item, M, W, unko);
		//cout << s << " " << tmp << endl;
		mp[minTime[s]] = max(mp[minTime[s]], tmp);
	}
	// dp
	for (int i = 0; i <= T; i++) {
		for (auto p : mp) {
			if (i+p.first <= T) {
				dp[i+p.first] = max(dp[i+p.first], dp[i] + p.second);
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= T; i++)
		ans = max(ans, dp[i]);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3428
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    int l,r;
    int num=0;
    rep(i,n){
        cin >> l >> r;
        num=num+(r-l)+1;
    }
    cout << num << endl;
    return 0;
}




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

using namespace std;

int main(){
  int n;
  cin >> n;
  bool ans=false;

  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      
      if(n==i*j){
        ans=true;
      }
    }
  }
  if(ans==true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }


  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
long long maxim(long long a, long long b) { return a > b ? a : b; }
int main(){
    long long a,b,v,w,t,i,dist;
    scanf("%lld %lld %lld %lld %lld",&a,&v,&b,&w,&t);
    dist=maxim(a-b,b-a);
    if(v<=w){
        printf("NO");
        return 0;
    }
    if(t*(v-w)<dist){
        printf("NO");
        return 0;
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 1728
n=int(input())
def dfs(s,st):
  if len(s)==n:
    return print(s)
  else:
    for i in range(ord('a'),ord(st)+1):
      if i==ord(st):
        dfs(s+chr(i),chr(ord(st)+1))
      else:
        dfs(s+chr(i),chr(ord(st)))
dfs('','a')

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int a;
	
	vector<int> w(10);
	vector<int> k(10);
	
	for(int i = 0; i < 10; i++){
		cin >> w[i];
	}
	
	for(int i = 0; i < 10; i++){
		cin >> k[i];
	}
	
	sort(w.begin(), w.end()); 
	sort(k.begin(), k.end());
	
	printf("%d %d\n",w[9]+w[8]+w[7],k[9]+k[8]+k[7]);
	
	return 0;
}

		

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const long long T=1e9;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	long long S, temp;
	int s, e, x1, y1, x2, y2;
	cin>>S;
	s=0, e=1e9;
	while(s<=e) {
		int m=(s+e)>>1;
		if(1LL*m*m>=S) e=m-1;
		else s=m+1;
	}
	temp=1LL*s*s-S;
	x1=y2=s;
	if(temp>1e9) {
		temp=1LL*s*(s-1)-S;
		y2=s-1;
	}
	cout<<"0 0 "<<x1<<" 1 "<<temp<<' '<<y2<<'\n';
	return 0;
}

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

int main() {
	int i,count=0;
	char S[11], T[12];
	scanf("%s", S);
	scanf("%s", T);
	count = strlen(T);
	if (strlen(S) + 1 == strlen(T)) {
		T[count-1] = '\0';
		if (strcmp(S, T) == 0) {
			printf("Yes");
		}
		else {
			printf("No");
		}
	}
	else {
		printf("No");
	}
	return 0;
}

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

const int MAX_N = 10000;
bool is_p[MAX_N+1] = {false,false};
int ans[MAX_N+1] = {0};

void sieve(){
	for(int i = 2 ; i <= MAX_N ; i++ )
		is_p[i] = true;
	for(int i = 2 ; i*i <= MAX_N ; i++ ){
		if( is_p[i] ){
			for(int j = i+i ; j <= MAX_N ; j += i ){
				is_p[j] = false;
			}
		}
	}
}

void f(){
	int p[1229], size = 0;
	for(int i = 2 ; i <= MAX_N ; i++ ){
		if( is_p[i] ) p[size++] = i;
	}
	
	for(int i = 0 ; i < size ; i++ ){
		int sum = 0;
		for(int j = i ; j < size ; j++ ){
			sum += p[j];
			if( sum >= MAX_N ) continue;
			ans[sum]++;
		}
	}
}

int main(){
	sieve();
	f();
	
	int n;
	while( cin >> n , n ){
		cout << ans[n] << endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <cmath>
#include <tuple>
#include <unordered_map>
#include <bitset>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define all(n)	n.begin(),n.end()
#define each(i,n) for(auto &i : n)

const int INF = 1e9;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

signed main() {

	int n, m, p, a, b;


	while (cin >> n >> m >> p >> a >> b && n) {
		typedef bitset<10> bit;
		vector<int> tb(10);
		int d[31][31];
		rep(i, 31)rep(j, 31) {
			d[i][j] = INF;
		}

		rep(i, n) {
			cin >> tb[i];
		}
		rep(i, p) {
			int x, y, z;
			cin >> x >> y >> z;
			d[x][y] = d[y][x] = z;
		}

		typedef pair<bit, int> bi;
		queue<bi> q;
		unordered_map<bit, double> me[31];
		q.push(bi(bit(), a));
		me[a][bit()] = 0;

		double ans = INF;
		while (q.size()) {
			int t = q.front().second;
			auto nb = q.front().first;
			q.pop();

			rep(i, m + 1) {
				if (d[t][i] != INF) {
					rep(j, n) {
						if (nb[j] == 0) {
							double time = double(d[t][i]) / double(tb[j]);
							auto tnb = nb;
							tnb[j] = 1;
							if (i == b) {
								ans = min(me[t][nb] + time, ans);
							}
							if (!me[i].count(tnb) || me[i][tnb] > me[t][nb] + time) {
								me[i][tnb] = me[t][nb] + time;
								q.push(bi(tnb, i));
							}
						}
					}
				}
			}
		}
		if (ans == INF) {
			cout << "Impossible" << endl;
		}
		else {
			cout << fixed << setprecision(30) << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3736
import sys
N, X, M = map(int, input().split())
ans = X
is_visited = [-1 for i in range(10**5+1)]
X_list = []
for i in range(0, N-1):
    X = (X ** 2) % M
    if is_visited[X] >= 0:
        remN = N-i-1
        ans += (remN // (i-is_visited[X])) * sum(X_list[is_visited[X]:])
        for j in range(is_visited[X], is_visited[X]+remN % (i-is_visited[X])):
            ans += X_list[j]
        print(ans)
        sys.exit()
    is_visited[X] = i
    X_list += [X]
    ans += X
    if X == 0:
        print(ans)
        sys.exit()
print(ans)

    


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

long long N;
int ans=0;
void dfs(long long s){
    bool three=false,five=false,seven=false;
    long long num=s;
    if(s>N){
        return;
    }
    while(num>0){
        if(num%10==3){three=true;}
        else if(num%10==5){five=true;}
        else if(num%10==7){seven=true;}
        else{ goto label; }
        num/=10;
    }
    if(three==true&&five==true&&seven==true){
        ans++;
    }
    label:;
    dfs(s*10+7);
    dfs(s*10+5);
    dfs(s*10+3);
}

int main(){
    cin>>N;
    dfs(0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define M 2000000
#define N 100000000
int heap[M+1],bel;
void maxHeap(int i){
  int temp,left,right,largest;
  left = 2*i;
  right = 2*i+1;
  if(left<=bel && heap[left] > heap[i]) largest = left;
  else largest = i;
  if(right<=bel && heap[right]>heap[largest]) largest = right;
  if(largest != i){  temp = heap[i]; heap[i] = heap[largest]; heap[largest] = t\
emp;
    maxHeap(largest);
  }
}
void Keykansu(int i,int key){
  int temp;
  heap[i] = key;
  while(i>1 && heap[i/2]<heap[i]){
    temp = heap[i]; heap[i] = heap[i/2];  heap[i/2] = temp;i /= 2;
  }
}
void insert(int key){
  bel++;
  heap[bel] = -N;
  Keykansu(bel,key);
}
void extract(){
  printf("%d\n",heap[1]);
  heap[1] = heap[bel--];
  maxHeap(1);
}
int main(){
  int total; char s[10];
  while(1){
    scanf("%s",s);
    if(s[0]=='e' && s[1]=='n') break;
    if(s[0]=='i'){
      scanf("%d",&total);
      insert(total);
    }
    if(s[0]=='e') extract();
  }
 return 0;
}


Measured memory_bytes: 5640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <map>
#include<queue>


const int INF = 1 << 28;
const long long MOD = 1000000007;
using namespace std;
using Graph = vector<vector<int>>;

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

vector<int> seen(50,-1);
int counter_for_dfs = 0;
void dfs(Graph &G, int v) {
	seen[v] = counter_for_dfs;
	counter_for_dfs++;
	for (auto v_next : G[v]) {
		if (seen[v_next]>=0)continue;

		dfs(G, v_next);
	}
}

void bfs(Graph &G) {
	vector<int> dist(G.size(), -1);
	queue<int> que;
	
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int g : G[v]) {
			if (dist[g] != -1)continue;
			dist[g] = dist[v] + 1;
			que.push(g);
		}
	}
	for (auto i : dist) {
		cout << i << " ";
	}
}

int counter[200005] = {};
void bfs2(Graph &G,int p,int x) {
	vector<int> dist(G.size() , -1);
	queue<int> que;
	
	dist[p] = 0;
	que.push(p);
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int g : G[v]) {
			if (dist[g] != -1)continue;
			dist[g] = dist[v] + 1;
			que.push(g);
			counter[g] += x;
		}
	}
}
long long int gcd(long long int a, long long int b) {
	long long int c = std::min(a, b);
	a = std::max(a, b);
	b = c;
	while (true) {
		c = a % b;
		a = b;
		b = c;
		if (c == 0)break;
	}
	return a;
}
int main()
{
	std::string x;
	std::cin >> x;
	for (int i = 0; i < x.length(); i++) {
		if (x.substr(i, 2) == "ST") {
			x.erase(i, 2);
			i = i >= 2 ? i - 2 : -1;
		}
	}
	std::cout << x.length();
}

Measured memory_bytes: 640
/*  
     author : hursh29    
     g++ : 17.3.20 
*/        
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << "\n"
#define speedup            ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x) 			   cout << x << "\n" ; 
#define MOD                998244353
#define pi                 pair<ll,ll>
#define vi                 vector <ll>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set; 
const int N = 2e5+7; 
/*   
    time : 17 : 28      
    date : 20.12.2019
*/    
ll n,mi_ = 1e13,i ;  
int solve(){
    cin >> n ; 
    for( i = 1 ; i*i  <= n   ; i++)
    	if(n%i == 0 )
    	mi_ = min(mi_,i+n/i) ;
    mi_ -= 2 ; 
    cout << mi_ ; 	 
    return 0 ; 
}
int main() { 
	speedup ;  
    int test  = 1 ; 
	//cin >> test  ; 
	while(test--)
    	solve() ; 
	 
	return 0;
} 


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

#define maxnum 100000
int main() {
    long long n,m;
    cin>>n>>m;
    long long v[100];
    long long w[100];
    for (int i=0;i<n;++i) {
        cin >>w[i] >>v[i];
    }
    long long a[maxnum + 1];
    bool flag[maxnum + 1];
    for (int i= 0;i<=maxnum;++i ){
        a[i] = m;
    }
    for (int i=0;i<n;++i){
        for (int j = maxnum -v[i]; j>0; --j) {
            if (a[j] != m ) {
                if (a[j] >= w[i]){
                    if (a[j+v[i]] == m) {
                        a[j+v[i]] = a[j] - w[i];
                    } else {
                        a[j+v[i]] = max(a[j+v[i]], a[j] - w[i]);
                    }
                }
            }
        }
        if (w[i] <= m) {
            if (a[v[i]] == m) {
                a[v[i]] = m - w[i];
            } else {
                a[v[i]] = max(a[v[i]], m - w[i]);
            }
        }
    }
    for (int i = maxnum ; i>=0; i--) {
        if (a[i] != m) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;

  int ans = ((l)+(l+n-1))*n/2;
  if (l <= 0 && abs(l) < n){
  }
  else if (l > 0){
    ans -= l;
  }
  else {
    ans -= (l+n-1);
  }
  cout << ans << endl;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n;cin>>n;
    double t=0;
    REP(i,n){
        double a;cin>>a;
        t += 1.0/a;
    }
    cout<<1.0/t<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,k;
	cin>>a>>b>>k;
	if(a<=k){
		k-=a;
		a=0;
		
	}
	else {
		a-=k;
		k=0;
	}
	//cout<<a<<" "<<k<<"\n";
	if(b<=k){
		b=0;
	}
	else{
		b-=k;
	}
	cout<<a<<" "<<b<<"\n";
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;

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

const int MX = 1<<19;

struct Tree{
	int t[MX*2];
	void update(int x, int v){
		x += MX;
		t[x] += v;
		while(x > 1) x /= 2, t[x] = max(t[x*2], 0) + max(t[x*2+1], 0);
	}
	int read(){ return t[1]; }
} tree;

int cnt[MX], D[MX];

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%d", D+i), cnt[D[i]]++;
	for(int i = N+1; i <= 2*N; i++) tree.update(i, -1);
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < cnt[i]; j++) tree.update(i-j+N, 1);
	}
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		int u = D[a], v = b;
		if( u != v ){
			D[a] = b;
			cnt[u]--; cnt[v]++;
			tree.update(u-cnt[u]+N, -1);
			tree.update(v-cnt[v]+1+N, 1);
		}

		printf("%d\n", tree.read());
	}
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
 
int main() {
    int H,W;
    cin>>H>>W;
    H+=2;
    W+=2;
    char s[H][W];
    REP(i,H)REP(j,W) {
        if (i == 0 || i == H-1 || j == 0 || j == W-1)
            s[i][j] = '.';
        else
            cin>>s[i][j];
    }
    FOR(i,1,H-1)FOR(j,1,W-1){
        if (s[i][j] == '#' && s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.' ) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t;
	const clock_t begin_time = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
  	if(n%m==0)
    {
      cout<<0<<endl;
    }
  else
  {
   cout<<1<<endl; 
  }
	//cout << float( clock () - begin_time ) /  CLOCKS_PER_SEC<<endl;
	return 0;
}  	

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


vector<int> edge[300000];
int dis[300000],flag[300000];

void add(int x,int y){
    edge[x].push_back(y+1);
    edge[x+1].push_back(y+2);
    edge[x+2].push_back(y);
}

struct node{
    int v,c;
    node(int _v=0,int _c=0):v(_v),c(_c){}
    bool operator < (const node & rhs) const{
        return c>rhs.c;
    }
};

void dijskra(int s,int t,int n)
{
    for (int i=0;i<n*3;++i) dis[i]=-1;
    priority_queue< node > _stack;
    _stack.push( node(s,0) );dis[s]=0;
    while (!_stack.empty()){
        node pii=_stack.top();_stack.pop();
        int now=pii.v;
        if (flag[now]) continue; flag[now]=1;
        for (int i=0;i<edge[now].size();++i){
            int to=edge[now][i];
            if (flag[to]==0 && (dis[to]==-1 || dis[to]>dis[now]+1)){
                dis[to]=dis[now]+1;
                _stack.push( node(to,dis[to]) );
            }
        }
    }
}


int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for (int i=0;i<m;++i){
        int t1,t2;scanf("%d%d",&t1,&t2);
        --t1;--t2;
        add(t1*3,t2*3);
    }
    int s,t;scanf("%d%d",&s,&t);
    --s;--t;
    s*=3;t*=3;
    dijskra(s,t,n);
    if (dis[t]%3==0) dis[t]/=3;
    printf("%d\n",dis[t]);
}



Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define reps(i,start,end,step) for(int i=start;i< end;i+=step)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define Pr(x) cout << x << endl
#define Prs(x) cout << x << " "



int main()
{
    ll n1, n2, N, M;
    cin >> n1 >> n2;
    if(n1 <= n2){
        N = n1;
        M = n2;
    }
    else{
        N = n2;
        M = n1;
    }
            
    ll ans =0;
    if ((N==1)&(M==1)) ans =1;
    else if((N==1)& (M>=2)) ans = M-2;
    else if((N==2)&(M==2)) ans = 0;
    else if((N==2)&(M>=3)) ans = 0;
    else if((N>=3)&(M>=3)) ans = (N-2) * (M-2);
    cout << ans  << endl;
    
    return 0;
}

Measured memory_bytes: 256
// 小数点以下の桁数を指定
// cout << fixed << setprecision(8);

#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
const double EPS = 1e-6;

int round(int y)
{
	y = min(y, 255);
	y = max(y, 0);
	return y;
}

int sq(int x)
{
	return x*x;
}

int dp[20001][256];

int main()
{
	int N, M;
	while (cin>>N>>M, N) {
		vector<int> C(M), x(N);
		rep(i, M) cin>>C[i];
		rep(i, N) cin>>x[i];
		
		
		fill(dp[0], dp[0]+20001*256, INF);
		
		for (int k=0; k<M; k++) {
			int y = round(128 + C[k]);
			dp[0][y] = sq(x[0]-y);
		}
		
		for (int i=1; i<N; i++) {
			for (int j=0; j<256; j++) {
				if (dp[i-1][j] >= INF) continue;
				for (int k=0; k<M; k++) {
					int y = round(j+C[k]);
					dp[i][y] = min(dp[i][y], dp[i-1][j]+sq(x[i]-y));
				}
			}
		}
		
		int ans=INF;
		for (int j=0; j<256; j++) {
			ans = min(dp[N-1][j], ans);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 21272
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
const int mx = 200005;
vv vec;
int s[mx],BIT[mx],id[mx],j=1;
int n,q,a,b;
void update(int idx,int x){
	for (int i = idx; i <= n; i+=(i&(-i)))
		BIT[i]+=x;
}
int get(int idx){
	int sum=0;
	for (int i = idx; i >= 1; i-=(i&(-i)))
		sum+=BIT[i];
	return sum;
}
void dfs(int node,int p){
	id[node]=j++;
	s[node]=1;
	for(auto it:vec[node]){
		if(it==p)continue;
		dfs(it,node);
		s[node]+=s[it];
	}
}
int main(){
	boost;
	cin>>n>>q;
	vec.resize(n);
	for (int i = 0; i < n-1; ++i)
	{
		cin>>a>>b;a--,b--;
		vec[a].pb(b),vec[b].pb(a);
	}
	dfs(0,0);
	while(q--){
		cin>>a>>b;
		a--;
		update(id[a],b);
		if(id[a]+s[a]<=n)update(id[a]+s[a],-b);
	}
	for (int i = 0; i < n; ++i)
		cout<<get(id[i])<<" ";
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 28032
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int n, c = 0, dis = 0;
	cin>>n;
	vi a(n);
	map<int, int> count;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		count[a[i]]++;
	}
	for(auto i:count)
	{
		dis++;
		if(i.se%2==0)
		{
			c++;
		}
	}
	if(c%2==0) p(dis);
	else p(dis-1);
	return 0;
}	

Measured memory_bytes: 5376
N, W = map(int, input().split())

WV = [tuple(map(int, input().split())) for _ in range(N)]
W0 = WV[0][0]
R = N * 3

dp = [[-10**18] * (R + 1) for _ in range(N + 1)]
dp[0][0] = 0

for w, v in WV:
    w -= W0
    for n in range(N)[::-1]:
        for i in range(R)[::-1]:
            if i + w <= R:
                dp[n + 1][i + w] = max(dp[n + 1][i + w], dp[n][i] + v)

ans = 0
for n in range(N + 1):
    for w in range(R + 1):
        if n * W0 + w <= W:
            ans = max(ans, dp[n][w])
print(ans)


Measured memory_bytes: 42076
S = input()
T = input()
m, n = len(S), len(T)
DP = [[0 for j in range(n+1)] for i in range(m+1)]
for i in range(1, m+1):
    for j in range(1, n+1):
        if S[i-1] == T[j-1]:
            DP[i][j] = DP[i-1][j-1] + 1
        else:
            DP[i][j] = max(DP[i][j-1], DP[i-1][j])
i, j = m, n
X = ''
while len(X) < DP[m][n]:
    if S[i-1] == T[j-1]:
        X = S[i-1] + X
        i -= 1
        j -= 1
    elif DP[i][j] == DP[i-1][j]:
        i -= 1
    elif DP[i][j] == DP[i][j]:
        j -= 1
print(X)


Measured memory_bytes: 119772